Application. Exit () End the program, but the thread is still working.

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.