Application.Current.Shutdown(-1)没有关闭WPF应用程序

Rel*_*ity 5 wpf application-shutdown

我正在检查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();
            }

        }
Run Code Online (Sandbox Code Playgroud)

Ed *_*tes 13

请改用Environment.Exit().那将尝试优雅地关闭,但如果不能优雅地关闭,将粗暴地关闭 - 强制终止线程.