开发者

Process not terminated at the end of the program

开发者 https://www.devze.com 2023-03-15 04:11 出处:网络
After I close the main window of my program, the process is still running in the background. 开发者_JAVA百科How can I check what is the cause for this weird problem?

After I close the main window of my program, the process is still running in the background. 开发者_JAVA百科How can I check what is the cause for this weird problem?

(I don't know which part of my program code is relevant)


First check that the value of your application's ShutdownMode property is equal to ShutdownMode.OnMainWindowClose -- if it is not, see if the actual value is preventing the app from closing.

If this does not solve the problem, then you have one or more non-background threads still running after the main window closes, preventing the process from shutting down. Break into the debugger and see how many threads are still alive and what they are doing; this will lead you to a solution.


To see the Thread that is currently running and stopping your application from termination just press "Break All" at the Visual Studio and see where the cursor stops.

Note: you can force application to terminate by calling Environment.Exit();


Another reason could be that someone set the Application.ShutdownMode to OnExplicitShutdown.


One possibility is that you create threads which are not set to background or you're calling code that does that; that may keep your process "alive" even after you shut down your main thread.

Make sure that you terminate all of your threads before you exit or you set their IsBackground property to true.

0

精彩评论

暂无评论...
验证码 换一张
取 消