本文整理汇总了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();
}
示例2: ShutdownAppWithFallback
void ShutdownAppWithFallback(int exitCode, Application app) {
try {
app.Dispatcher.Invoke(() => app.Shutdown(exitCode));
} catch (Exception) {
_exitHandler.Exit(exitCode);
}
}
示例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();
}
示例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();
}
示例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();
}
}
示例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);
}
示例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);
}
示例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;
}
示例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();
}
}
示例10: menuExit
public void menuExit(object sender, RoutedEventArgs args)
{
app = (Application)System.Windows.Application.Current;
app.Shutdown();
}
示例11: MenuExit
public void MenuExit(object sender, RoutedEventArgs args)
{
_app = Application.Current;
_app.Shutdown();
}