【发布时间】:2014-10-23 08:48:52
【问题描述】:
当我需要退出WPF Application 时,我通常使用Application.Current.Shutdown(),但有时Application.Current 是NULL,我也尝试过Environment.Exit(0),但它不能正常工作。
当Application.Current 是NULL 时,还有其他方法可以退出WPF Applicationspecialy 吗?
这是我的代码:
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
if (something)
{
continue....
}
else
{
Application.Current.Shutdown()
}
}
【问题讨论】:
-
从什么上下文中调用 Application.Current?你能发布你正在使用的代码吗?
-
我想关闭我的整个应用程序!对于任何
AppDomain,只有一个System.Windows.Application。 -
你有没有试过 this.Close(); ??
-
@apomene:你这是什么意思?我在
App.xaml中使用此代码,而在此处不使用此代码!!! -
我第一次听说
Application.Current可以为空。至少在加载主窗口之后,Application.Current没有理由为空。
标签: wpf