C # Background threads, foreground threads

Source: Internet
Author: User
Tags thread class

Class Program {static void Main (string[] args) {/* background thread * As long as one foreground thread is running, the application is running * Multiple foreground threads running, the Main () method ends and the application process is activated until the foreground thread finishes As a task * Default: Thread class creates threads that are foreground threads, and thread pools are background threads/thread T1 = new Thread (ThreadMain); T1. Name = "66"; Set to foreground thread T1. IsBackground = false; T1. Start (); Console.WriteLine ("Main thread end.") "); /* Run to see although the main thread main () method has finished exiting * But the entire program still continues to run until the T1 thread (foreground thread) is created to exit the program * if set T1. IsBackground = True to create a background thread, the main thread main () method ends * The entire program exits regardless of whether the created T1 thread (background thread) is running to completion/} static void ThreadMain () {Console.writel INE ("thread start" + Thread.CurrentThread.Name); Thread.Sleep (5000); Console.WriteLine ("Thread complete.") "+ Thread.CurrentThread.Name);}}

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.