Thread.IsAlive and Thread.ThreadState == ThreadState.Running

I use to check the status of a thread using if(Thread.IsAlive) . A form is running in this thread. Sometimes at run time, although the form remains open, a call to Thread.IsAlive seems to be evaluated as false. I decided to do the same check with if(Thread.ThreadState==ThreadState.Running) . Is this the right way? If not, what is the possible work around?

+7
source share
1 answer

msdn The Thread.IsAlive property is true if this thread is started and does not complete normally or is interrupted; otherwise false.

msdn Thread.ThreadState

  • Launch
    The thread is started, it is not blocked, and there is no ThreadAbortException pending.
  • StopRequested
  • SuspendRequested
  • Background
  • Not started
  • WaitSleepJoin
  • Suspension
  • Abortrequested

I think it’s now clear that Running is not the same as IsAlive

+11
source

All Articles