How to close a child thread when a C # program shuts down

Source: Internet
Author: User

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

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.