Application.Current.Shutdown(-1) 不关闭 WPF 应用程序 [英] Application.Current.Shutdown(-1) not closing WPF app
问题描述
我正在检查 Windows 身份验证用户是否是我的 wpf 应用程序的有效用户.
I am checking if the windows authenticated user is a valid user for my wpf application or not.
如果没有,我需要关闭应用程序;但即使在执行 Application.Current.Shutdown(-1) 之后,应用程序仍继续愉快地执行.
If not, I need to shut down the application; but even after executing Application.Current.Shutdown(-1) the application keeps on executing happily.
下面的链接说我需要删除我的 StartUpURI;但我的 app.xaml 中没有那个标签.-> 从 App.xaml.cs 关闭 WPF 应用程序
The below link says that I need to remove my StartUpURI; but I dont have that tag in my app.xaml. -> Shutting down a WPF application from App.xaml.cs
-我在 APP.XAML.CS 中有这段代码 ->
EDIT :- I have this code in APP.XAML.CS ->
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
this.exceptionPolicy = ConfigurationManager.AppSettings.Get("ExceptionPolicy");
this.displayErrorDetails = true;
this.container = new UnityContainer();
// Register services and types in Unity
RegisterServices();
// Check user
if (!IsValidUser())
{
//Application.Current.Shutdown();
App.Current.Shutdown();
}
}
推荐答案
使用 环境.Exit() 代替.这将尝试正常关闭,但如果不能正常关闭,则会粗暴地关闭 - 强行终止线程.
Use Environment.Exit() instead. That will try to shut down gracefully, but if it can't gracefully, will shut down rudely -- forcefully terminating threads.
这篇关于Application.Current.Shutdown(-1) 不关闭 WPF 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!