Thread status and its conversion

Source: Internet
Author: User

The thread object uses the ThreadState property to indicate the thread status.

ThreadState is an enumeration type object with the flag feature. Therefore, bitmask must be used to determine the current state of the thread. as a special case, because the bit code of the Running state is 0, determine whether the thread is running in the following way: (myThread. threadState & (ThreadState. stopped | ThreadState. unstarted) = 0.

The enumerated members are as follows:

 

  Member name Description
  Running The thread has been started, it is not blocked, and there is no pendingThreadAbortException.
  StopRequested The thread is being requested to stop. This is for internal use only.
  SuspendRequested The thread is being requested to suspend.
  Background The thread is being executed as a background thread, as opposed to a foreground thread. This state is controlled by setting theThread. IsBackground property.
  Unstarted The Thread. Start method has not been invoked on the thread.
  Stopped The thread has stopped.
  WaitSleepJoin The thread is blocked. this cocould be the result of calling Thread. sleep orThread. join, of requesting a lock-for example, by callingMonitor. enter orMonitor. wait-or of waiting on a thread synchronization object such asManualResetEvent.
  Sushortded The thread has been suincluded.
  AbortRequested The Thread. Abort method has been invoked on the thread, but the thread has not yet initialized ed the pendingSystem. Threading. ThreadAbortException that will attempt to terminate it.
  Aborted The thread state already des AbortRequested and the thread is now dead, but its state has not yet changed toStopped.

 

The status transition diagram is as follows:

Related Article

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.