【发布时间】:2011-07-06 19:31:02
【问题描述】:
我正在检查 Windows 身份验证用户是否是我的 wpf 应用程序的有效用户。
如果没有,我需要关闭应用程序;但即使在执行 Application.Current.Shutdown(-1) 之后,应用程序也会继续愉快地执行。
下面的链接说我需要删除我的 StartUpURI;但我的 app.xaml 中没有那个标签。 -> Shutting down a WPF application from App.xaml.cs
编辑:- 我在 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();
}
}
【问题讨论】:
-
你需要显示
Application.Current.Shutdown()周围的代码。问题可能与您从哪里调用它有关。 -
我的代码在 App.Xaml -> OnStartup(StartupEventArgs e)
-
您可以发布您的整个 App.xaml.cs 文件内容吗?
-
您正在寻找哪个特定代码?...因为复制整个代码会搞砸事情。
-
现在请把整个
OnStartup方法。只需在每行前面放置 4 个空格以使其格式正确。如果这还不够显示,其中的代码可能会告诉我们还需要查看什么。