C # multithreading Study Notes (2)

Source: Internet
Author: User
A. Other threads are attached to the thread where the Main () function is located.
The Main () function is the entry of the C # program. The starting thread can be called the Main thread.
If all foreground threads are stopped, the main thread can be terminated, and all background threads will be terminated unconditionally.
While all threads are executed in a serial way at the micro level, you can think of them as being executed in parallel at the macro level.

B. The Thread. ThreadState may be used to access the current state of the Thread.

  • Aborted: the thread has stopped.
  • AbortRequested: The Thread. Abort () method of the Thread has been called, but the Thread has not stopped.
  • Background: The Thread is executed in the Background, which is related to the attribute Thread. IsBackground.
  • Running: The thread is Running normally.
  • Stopped: the thread has been Stopped.
  • StopRequested: The thread is being requested to stop
  • Suincluded: the thread has been Suspended. (In this status, you can call Resume () to run the thread again)
  • SuspendRequested: The thread is requesting to be suspended, but cannot respond.
  • Unstarted: Thread. Start () is not called to Start the Thread.
  • WaitSleepJoin: The thread is blocked because it calls methods such as Wait (), Sleep (), and Join ().

    C. The difference between background threads and foreground threads is that
    The background thread does not prevent program termination. Once all foreground threads of a process are terminated, CLR (general language runtime environment) will completely terminate the process by calling the Abort () method of any surviving background process.

    D. Set the Thread priority.
    When the threads compete for the CPU time, the CPU is given the service according to the priority of the thread. In the C # application, you can set five different priorities, from high to low, which are Highest, AboveNormal, Normal, BelowNormal, Lowest,
    If the priority is not specified during thread creation, the system defaults to ThreadPriority. Normal. Specify a priority for a thread
    We can use the following code to set the thread priority.

    // Set the priority to the lowest
    MyThread. Priority = ThreadPriority. Lowest;
  • 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.