cid#1606940 Check of thread-shared field evades lock acquisition
[LibreOffice.git] / odk / examples / DevelopersGuide / OfficeDev / TerminationTest / csharp / TerminationTest.cs
blob2829514b104a0e00a0bdca90b521f3a30f2c426e
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
9 using System;
11 using com.sun.star.frame;
12 using com.sun.star.lang;
13 using com.sun.star.uno;
15 public class Program
17 public static bool atWork = false;
19 private static int Main()
21 try
23 // Connect to a new instance of the Office
24 XComponentContext context = NativeBootstrap.bootstrap();
25 Console.WriteLine("Connected to a running office...");
27 // Get a reference to the Desktop service
28 XDesktop2 desktop = Desktop.create(context);
30 // Create our termination request listener, and register it
31 TerminateListener listener = new TerminateListener();
32 desktop.addTerminateListener(listener);
34 // Try to terminate while we are at work.
35 atWork = true;
36 bool terminated = desktop.terminate();
37 Console.WriteLine("The Office {0}", terminated
38 ? "has been terminated"
39 : "is still running, we are at work");
41 // Try to terminate when we are NOT at work.
42 atWork = false;
43 terminated = desktop.terminate();
44 Console.WriteLine("The Office {0}", terminated
45 ? "has been terminated"
46 : "is still running. Something else prevents termination, such as the quickstarter.");
48 return 0;
50 catch (Exception ex)
52 Console.Error.WriteLine(ex);
54 return 1;