为什么在显示WinForms对话框后,我的WPF应用程序不会正常关闭? [英] Why won't my WPF application close properly after it displays a WinForms dialog?

查看:151
本文介绍了为什么在显示WinForms对话框后,我的WPF应用程序不会正常关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WPF应用程序中使用了第三方WinForms登录对话框,由于某些原因,这使得我的WPF应用程序在调试时无法正确关闭。



如果我退出Winforms登录对话框之前,登录,应用程序正确关闭,但是如果登录成功并启动WPF窗口,退出窗口不会关闭该应用程序。



我将 OnExit 方法中的断点放在 App 它永远不会被调用。我覆盖了我的主窗口的 OnClosing 方法,并且确实被调用,但是甚至调用 Application.Current.ShutDown()不正确退出应用程序。我也尝试将我的应用程序的 ShutdownMode 设置为 OnExplicitShutdown OnMainWindowClose 并且都没有关闭它。



我唯一的提示是在Debug窗口中显示以下内容,但我不知道该怎么告诉我。

 线程vshost.RunParkingWindow(0xf74)已退出代码0(0x0)。 
线程< No Name> (0x1b58)已退出代码0(0x0)。

此行为仅在Visual Studio中以调试模式运行时发生。没有调试运行应用程序会正确关闭应用程序。



任何人都可以指出正确的方向,可能导致此行为?



编辑



WinForms登录对话框不是传统的登录对话框,其中包含 Show ) Close()方法,它是一个静态类,只有一个 Login() Logout()方法。



它被这样使用:

  if(CompanyNamespace.ApplicationName.Login())
{
var shell = new ShellView();
var context = new ShellViewModel();
shell.DataContext = context;
shell.Show();

//当Shell窗口关闭时,调试器不会停止
}
else
{
Application.Current.Shutdown(); //工作正常
}


解决方案



你可以尝试 System.Environment.Exit(0)


I am using a 3rd party WinForms Login Dialog in my WPF app, and for some reason this is making my WPF application not close correctly when debugging.

If I exit the winforms login dialog prior to logging in, the application closes correctly, however if I login successfully and launch the WPF window, exiting the window does not shut down the application.

I put a breakpoint in the OnExit method of App and it never gets called. I overwrote the OnClosing method of my main window, and that does get called but even calling Application.Current.ShutDown() doesn't exit the application correctly. I have also tried setting my App's ShutdownMode to OnExplicitShutdown and OnMainWindowClose and neither of those shut it down.

The only hint I have is the following appears in the Debug window, but I have no idea what it's trying to tell me.

The thread 'vshost.RunParkingWindow' (0xf74) has exited with code 0 (0x0).
The thread <No Name> (0x1b58) has exited with code 0 (0x0).

This behavior only occurs when running in Debug mode in Visual Studio. Running the app without debugging closes the app correctly.

Can anyone point me in the right direction as to what could be causing this behavior?

Edit

The WinForms login dialog is not a traditional login dialog with a Show() or Close() method, it's a static class that only has a Login() and Logout() method.

It's used by someething like this:

if (CompanyNamespace.ApplicationName.Login())
{
    var shell = new ShellView();
    var context = new ShellViewModel();
    shell.DataContext = context;
    shell.Show();

    // When the Shell Window gets closed, the debugger doesn't stop
}
else
{
    Application.Current.Shutdown(); // Works fine
}

解决方案

this sounds stupid, but have you tried to call winformsLoginDialog.Close(); in the onClosing method of your main window? I suspect the winforms login dialog still has a thread running, and/or the form may have been hidden instead of closed.

You could try System.Environment.Exit(0)

这篇关于为什么在显示WinForms对话框后,我的WPF应用程序不会正常关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆