WPF 应用程序未正确关闭

发布于 2024-07-18 04:12:27 字数 169 浏览 3 评论 0原文

我正在从使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

夏尔 2024-07-25 04:12:27

尝试使用 Environment.Exit(0) 代替

Try Environment.Exit(0) instead

薄凉少年不暖心 2024-07-25 04:12:27

您是否创建了任何线程来进行后台处理? 如果有,请确保为其设置 .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

长发绾君心 2024-07-25 04:12:27

不要忘记添加以下内容:

private void Window_Closed(object sender, EventArgs e)
{
  Application.Current.Shutdown();
}

希望这有帮助。

Don't forget to add this:

private void Window_Closed(object sender, EventArgs e)
{
  Application.Current.Shutdown();
}

Hope this helps.

不回头走下去 2024-07-25 04:12:27

如果您的应用程序中有多个窗口或对话框,您可能需要显式关闭每个窗口或对话框。

关闭对话框:

_myDialog.Close();

关闭所有窗口:

foreach(var window in Application.Current.Windows.ToList())
{
    window.Close();
}

If you have multiple windows or dialogs in your application, you may need to close each one explicitly.

Close dialogs with:

_myDialog.Close();

Close all windows:

foreach(var window in Application.Current.Windows.ToList())
{
    window.Close();
}
骄傲 2024-07-25 04:12:27

我遇到一个问题,即使主窗口关闭,应用程序也不会关闭。 事实证明,我在启动屏幕上执行了 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.

╰つ倒转 2024-07-25 04:12:27

我遇到了同样的问题,尽管应用程序关闭,但应用程序进程并未停止。

就我而言,我从BackgroundWorker(下面的代码)打开了一个窗口,

BackgroundWorker BG = new BackgroundWorker();
BG.DoWork += new DoWorkEventHandler(BG_DoWork);
StockMinWindow MinWindow = new StockMinWindow(null); -------- this is the problem 
BG.RunWorkerAsync();

在运行BackgroundWorker之前实例化该窗口似乎不是问题,但是通过擦除应用程序正确关闭的行,

我从BackgroundWorker打开我的窗口,但使用主线程(下面的代码) )

 View.Dispatcher.BeginInvoke(new Action(delegate()
 {
   StockMinWindow MinWindow = new StockMinWindow(StockMinList);
   MinWindow.Owner = View;
   MinWindow.ShowDialog();
 }));

希望能帮助到你。

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)

BackgroundWorker BG = new BackgroundWorker();
BG.DoWork += new DoWorkEventHandler(BG_DoWork);
StockMinWindow MinWindow = new StockMinWindow(null); -------- this is the problem 
BG.RunWorkerAsync();

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)

 View.Dispatcher.BeginInvoke(new Action(delegate()
 {
   StockMinWindow MinWindow = new StockMinWindow(StockMinList);
   MinWindow.Owner = View;
   MinWindow.ShowDialog();
 }));

Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文