当前位置: 首页>>代码示例>>C#>>正文


C# Application.Shutdown方法代码示例

本文整理汇总了C#中System.Windows.Application.Shutdown方法的典型用法代码示例。如果您正苦于以下问题:C# Application.Shutdown方法的具体用法?C# Application.Shutdown怎么用?C# Application.Shutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Application的用法示例。


在下文中一共展示了Application.Shutdown方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

		static void Main()
		{
			//the WPF application object will be the main UI loop
			System.Windows.Application wpfApplication = new System.Windows.Application
			{
				//otherwise the application will close when all WPF windows are closed
				ShutdownMode = ShutdownMode.OnExplicitShutdown 
			};
			SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext());

			//set the WinForms properties
			//notice how you don't need to do anything else with the Windows Forms Application (except handle exceptions)
			System.Windows.Forms.Application.EnableVisualStyles();
			System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
			
			WpfProgramAddWinForms p = new WpfProgramAddWinForms();
			p.ExitRequested += (sender, e) =>
			{
				wpfApplication.Shutdown();
			};

			Task programStart = p.StartAsync();
			HandleExceptions(programStart, wpfApplication);

			wpfApplication.Run();
		}
开发者ID:ittray,项目名称:LocalDemo,代码行数:26,代码来源:WpfProgramAddWinForms.cs

示例2: ShutdownAppWithFallback

 void ShutdownAppWithFallback(int exitCode, Application app) {
     try {
         app.Dispatcher.Invoke(() => app.Shutdown(exitCode));
     } catch (Exception) {
         _exitHandler.Exit(exitCode);
     }
 }
开发者ID:MaHuJa,项目名称:withSIX.Desktop,代码行数:7,代码来源:WpfShutdownHandler.cs

示例3: Main

		static void Main()
		{
			//The WinForms Application will be the main UI loop
			System.Windows.Forms.Application.EnableVisualStyles();
			System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
			SynchronizationContext.SetSynchronizationContext(new WindowsFormsSynchronizationContext());

			//it's more awkward to have WinForms run the show; in certain cirumstances, if you don't change the WPF Application shutdown mode,
			//the application will be destroyed when that window is closed (because of the default "OnLastWindowClose")
			//then when you open a second WPF window...boom
			System.Windows.Application wpfApplication = new System.Windows.Application
			{
				//comment out this line to test, then click the button on the form to show another WPF window
				ShutdownMode = ShutdownMode.OnExplicitShutdown
			};
			
			WinFormsProgramAddWpf p = new WinFormsProgramAddWpf();
			p.ExitRequested += (sender, e) =>
			{
				System.Windows.Forms.Application.ExitThread();
			};

			Task programStart = p.StartAsync();
			HandleExceptions(programStart);


			System.Windows.Forms.Application.Run();
			//now the wpf application can also shut down
			wpfApplication.Shutdown();
		}
开发者ID:ittray,项目名称:LocalDemo,代码行数:30,代码来源:WinFormsProgramAddWpf.cs

示例4: RunUnderApplication

 static void RunUnderApplication(Activity activity)
 {
     Application application = new System.Windows.Application() { ShutdownMode = ShutdownMode.OnExplicitShutdown };
     application.Startup += delegate
     {
         WorkflowApplication wfApp = new WorkflowApplication(activity);
         wfApp.SynchronizationContext = SynchronizationContext.Current;
         wfApp.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
         {
             application.Shutdown();
         };
         wfApp.Run();
     };
     application.Run();
 }
开发者ID:tian1ll1,项目名称:WPF_Examples,代码行数:15,代码来源:Program.cs

示例5: HandleExceptions

		private static async void HandleExceptions(Task task, Application wpfApplication)
		{
			try
			{
				await Task.Yield(); //ensure this runs as a continuation
				await task;
			}
			catch (Exception ex)
			{
				//deal with exception, either with message box
				//or delegating to general exception handling logic you may have wired up 
				//e.g. to app.DispatcherUnhandledException and AppDomain.UnhandledException
				MessageBox.Show(ex.ToString());

				wpfApplication.Shutdown();
			}
		}
开发者ID:ittray,项目名称:LocalDemo,代码行数:17,代码来源:Program6.cs

示例6: TemplatedParent_Should_Be_Set_On_Template_Root

        public void TemplatedParent_Should_Be_Set_On_Template_Root()
        {
            Window target = new Window();
            Application app = new Application();
            bool passed = false;

            target.Loaded += (s, e) =>
            {
                FrameworkElement templateRoot = VisualTreeHelper.GetChild(target, 0) as FrameworkElement;
                passed = templateRoot.TemplatedParent == target;
                app.Shutdown();
            };

            app.Run(target);

            Assert.IsTrue(passed);
        }
开发者ID:modulexcite,项目名称:Avalonia,代码行数:17,代码来源:FrameworkElement_TemplateTests.cs

示例7: Show

        public void Show(string uriString)
        {
            if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
            {
                var message = "Please set STAThreadAttribute on application entry point (Main method)";
                Console.WriteLine(message);
                throw new InvalidOperationException(message);
            }

            _app = new Application();
            _window = new Window();
            var browser = new WebBrowser();
            _window.Content = browser;

            browser.Loaded += (sender, eventArgs) =>
            {
                browser.Navigate(uriString);
                SetForegroundWindow(new WindowInteropHelper(_window).Handle);
            };

            browser.Navigating += (sender, eventArgs) =>
            {
                if (this.Navigating != null)
                {
                    this.Navigating(this, eventArgs);
                }
            };

            browser.Navigated += (sender, eventArgs) =>
            {
                if (this.Navigated != null)
                {
                    this.Navigated(this, eventArgs);
                }
            };

            _window.Closed += (sender, eventArgs) => _app.Shutdown();

            _app.Run(_window);
        }
开发者ID:brain2cpu,项目名称:OneDriveRestAPI,代码行数:40,代码来源:BrowserWindow.cs

示例8: ShowWindow

        public static async Task ShowWindow(Version version, IInstallerFactory factory, string logPath)
        {
            var tcs = new TaskCompletionSource<object>();
            var thread = new Thread(() => 
            {
                try
                {
                    var application = new Application();                    
                    var installerWindow = new MainWindow(factory, version, () => application.Dispatcher.Invoke(() => application.Shutdown()), logPath);
                    application.Run(installerWindow);
                }
                finally
                {
                    tcs.TrySetResult(new object());
                }                
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();

            await tcs.Task;
        }
开发者ID:fusetools,项目名称:Squirrel.Windows,代码行数:22,代码来源:InstallerWindow.cs

示例9: CheckForRunningMoni

 private void CheckForRunningMoni(Application app)
 {
     var myName = Process.GetCurrentProcess().ProcessName;
     var sameNameProcesses = Process.GetProcessesByName(myName);
     if (sameNameProcesses.Length > 1)
     {
         MessageBox.Show("MONI läuft schon. Mit zwei laufenden MONIs haste nur Ärger...Tschö", "Problem");
         app.Shutdown();
     }
 }
开发者ID:dotob,项目名称:moni,代码行数:10,代码来源:AppHelper.cs

示例10: menuExit

 public void menuExit(object sender, RoutedEventArgs args)
 {
     app = (Application)System.Windows.Application.Current;
         app.Shutdown();
 }
开发者ID:samgonzalezr,项目名称:WPFSamples,代码行数:5,代码来源:Default.xaml.cs

示例11: MenuExit

 public void MenuExit(object sender, RoutedEventArgs args)
 {
     _app = Application.Current;
     _app.Shutdown();
 }
开发者ID:ClemensT,项目名称:WPF-Samples,代码行数:5,代码来源:Default.xaml.cs


注:本文中的System.Windows.Application.Shutdown方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。