One, in the actual coding will encounter this problem:
When the client closes the program, the main thread shuts down directly, regardless of the child thread.
However , in the Task Manager, the main program process is still running (at the end of the child thread, and the child threads are made while (1), etc.)
Second, when the main thread closes processing, the child thread is first closed.
The code looks like this:
Private void Main_formclosing (object sender, FormClosingEventArgs e) { ifnull && flowthread.isalive) Flowthread.abort (); This . Dispose ();}
But will encounter the main program shut down, similar to the state of the crash
Iii. forcing a process with the same name to be stopped at program startup
// Get all Processes foreach inch processes) { if"watermonitoris_weiding" && p.starttime < DateTime.Now.AddMinutes (-2)) { p.kill (); } }
Iv. assigning a thread to NULL
Private void Main_formclosing (object sender, FormClosingEventArgs e) { null; This . Dispose ();}
The highest version of the force, using one of the thread object's IsBackground property, set to True, when the main thread is closed, the sub-thread closes, fast.
true;
Reference post: http://blog.csdn.net/effectiveagui/article/details/7841792
How to close a child thread when a C # program shuts down