How to infer the current state of a thread in C #

Source: Internet
Author: User

how to infer the current state of a thread in C #
                                          sinom in C #. Thread Object thread uses the ThreadState property to indicate the thread state. Itis an enumerated type object with the Flags attribute.

ThreadState defines a set of all possible execution states for a thread. Once the thread is created. It is at least in one of the states . Until terminated.

Threads created in the common language execution are initially in the unstarted state. The external thread that enters execution is already in the running state.

The unstarted thread can be converted to the running state by calling start. Not all combinations of threadstate values are valid; For example, threads cannot be in aborted and unstarted states at the same time.Therefore, it is inferred that the current state of the thread must be inferred using the bitmask bitwise operation and cannot be inferred directly using equality.
define threadstate such as the following:   
       1. Infer if the thread is in a canceled state A. Incorrect inference (mythread.threadstate = = threadstate.abortrequested)   B. Correct inference(myThread.ThreadState & threadstate.abortrequested)! = 0
   2. Infer whether the thread is in the execution state      This one is a little special. Because threadstate.running equals 0. The & operation is not possible, so inference can be made using the following method: (mythread.threadstate = = ThreadState. Running)

How to infer the current state of a thread in C #

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.