WPF 应用程序未正确关闭
我正在从使用 ObjectDataProvider
绑定到 xaml 窗口的类调用 Application.Current.Shutdown()
,但应用程序未关闭。 谁能帮助我理解为什么? 主窗口关闭后,我的应用程序没有完全关闭,它也没有从任务管理器的进程列表中消失。
I am calling Application.Current.Shutdown()
from a class that is bound to xaml windows with ObjectDataProvider
, but the application is not closing. Can anyone help me to understand why? My application is not closing completely after my main window is closed, it doesn't disappear from task manager's process list.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
尝试使用
Environment.Exit(0)
代替Try
Environment.Exit(0)
instead您是否创建了任何线程来进行后台处理? 如果有,请确保为其设置
.IsBackground
属性,否则它们可能会保持应用程序运行Have you created any threads to do background processing? If you have, make sure to set the
.IsBackground
property on them, or they can keep the app running不要忘记添加以下内容:
希望这有帮助。
Don't forget to add this:
Hope this helps.
如果您的应用程序中有多个窗口或对话框,您可能需要显式关闭每个窗口或对话框。
关闭对话框:
关闭所有窗口:
If you have multiple windows or dialogs in your application, you may need to close each one explicitly.
Close dialogs with:
Close all windows:
我遇到一个问题,即使主窗口关闭,应用程序也不会关闭。 事实证明,我在启动屏幕上执行了 Hide() 而不是 Close(),因此它仍然潜伏在后台,保持应用程序处于活动状态。
I had a problem where the application would not shut down even when main window was closed. It turned out I had done Hide() on the splash screen instead of Close() so it was still lurking in the background keeping the application alive.
我遇到了同样的问题,尽管应用程序关闭,但应用程序进程并未停止。
就我而言,我从BackgroundWorker(下面的代码)打开了一个窗口,
在运行BackgroundWorker之前实例化该窗口似乎不是问题,但是通过擦除应用程序正确关闭的行,
我从BackgroundWorker打开我的窗口,但使用主线程(下面的代码) )
希望能帮助到你。
I had the same problem, the application process doesn't stop although the application closed.
In my case I opened a window from a BackgroundWorker (code below)
instanciate the window before running the BackgroundWorker seem not being the problem but by erasing the line the application closed correctly
I open my window from the BackgroundWorker but using the principal Thread (code below)
Hope it helps.