5

我正在检查 Windows 身份验证用户是否是我的 wpf 应用程序的有效用户。

如果没有,我需要关闭应用程序;但即使在执行 Application.Current.Shutdown(-1) 之后,应用程序也会继续愉快地执行。

下面的链接说我需要删除我的 StartUpURI;但我的 app.xaml 中没有那个标签。->从 App.xaml.cs 关闭 WPF 应用程序

编辑:- 我在 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();
            }

        }
4

2 回答 2

13

改用Environment.Exit()。这将尝试优雅地关闭,但如果它不能优雅地关闭,则会粗鲁地关闭——强行终止线程。

于 2011-07-06T19:53:47.120 回答
0

我从来没有运气在启动时关闭某些东西。我建议启动一个新线程,在短暂延迟后,使用示例中的类似代码关闭应用程序。

于 2011-07-06T20:01:13.690 回答