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.