To forcibly shut down all threads in a multithreaded application in dotnet

Source: Internet
Author: User
Tags dotnet
To forcibly shut down all threads in a multithreaded application in dotnet

For multithreaded applications, if you click the "Close" button directly in the upper-right corner or use "This.close ()" To exit the program, if a child thread is still working on the data, the main program window closes, but the process of the program does not exit, which allows us to The process is found in and forcibly closed.

Of course, for some programs, this situation does not matter, after the main window is closed, the child thread has not finished running, all child threads are running closed, the process of the program will automatically shut down, so as to avoid losing the data being processed in the child threads.

But, sometimes, we want to force out all the threads immediately, at this time, we can add a sentence before This.close ():
System.Diagnostics.Process.GetCurrentProcess (). Kill ();
Note: Before using the above method, make sure that the data you are working on in the child thread is lost that you can afford.

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.