The following are my experiences for reference only. Most of the reasons for this are the use of multi-threaded programming, or the dll you call uses multiple threads. We know that a thread is usually closed after the specified task is executed. However, in this case, we need to manually disable it. Use one of the following three methods to forcibly close the thread. Application. ExitThread (); // exit the message loop on the current thread and close all windows on the thread. System. environment. exit (0); // terminate the current Process and provide the specified Exit code Process for the basic operating system. getCurrentProcess (). kill (); // terminate the currently running thread, but these methods are forcibly disabled. How can we use Application. exit (); normally close the entire program? At this time, we will reference Microsoft's Application. exit (); explains Application. exit (); // The method stops all message loops running on all threads and closes all windows of the application, stop all message loops running on all threads. Since it is all, why can't it be closed? Here we need to clarify that the new process belongs to another domain. What you need to know is that the process is not equal to the thread, application. exit (); it is to close all threads of the current process and cannot close the processes it creates. The new process has nothing to do with this process. Therefore, we can understand Application in this way. exit (); Application. exit (); // The method stops all message loops running on all threads of the current process, and closes all windows of applications on the current process. Therefore, we want to use Application on the current process. exit (); To close other processes, you must set other processes as the IsBackground of the current process. When a thread is created in the main thread, the IsBackground of this thread is set to FALSE by default. When the main thread exits, the thread with IsBackground = FALSE continues until the thread execution ends. Only IsBackground = \ '# \' "/div>. isBackground = \ '# \' ". Therefore, after creating a process, add the following sentence: isBackground = \ '# \' "/div> before it can be controlled by the current process, and then can use Application. exit (); end. This article was first published in the 51cto --. Net Forum. Reprinted with the text description.
This article is from the "Coders 'text" blog, please be sure to keep this source http://rozbo.blog.51cto.com/2201536/1054368