简体   繁体   English

重新启动Windows窗体应用程序

[英]Restarting windows form application

i have a windows application C#4.0 with multithreadings problem is when i close the application ,the process stays on, no matter what i do so i have to do this: 我有一个带有多线程的Windows应用程序C#4.0,问题是当我关闭该应用程序时,该过程仍然存在,无论我做什么,我都必须这样做:

environment.exit(1);

or the process wouldnt close, 否则进程将无法关闭,

problem is if i executed environment.exit(1) then application.restart() wouldn't work then. 问题是,如果我执行了environment.exit(1),那么application.restart()将无法正常工作。

any idea how to kill the process and then restart ? 任何想法如何杀死该进程,然后重新启动?

Use the debugger. 使用调试器。 After you closed your main window, use Debug + Break All. 关闭主窗口后,使用Debug + Break All。 Debug + Windows + Threads. 调试+ Windows +线程。 Look at the call stack of the threads you see listed there to find the one that is preventing the program from terminating. 查看在那里列出的线程的调用堆栈,以查找阻止程序终止的线程。

Make sure to make all your worker threads run in the background (set IsBackground to true before starting them). 确保使所有辅助线程在后台运行(在启动它们之前将IsBackground设置为true)。 Background threads don't prevent the process from exiting. 后台线程不会阻止进程退出。

You can Exit application completely by typing this: 您可以通过键入以下命令完全退出应用程序:

Application.Exit();

For Restarting Application Completely: 要完全重新启动应用程序:

Application.Restart();

应用程序创建的线程必须在退出应用程序之前终止,否则挂起的线程将占用CPU和/或内存

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM