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

Victor Mukherjee picture Victor Mukherjee · Apr 26, 2013 · Viewed 42.6k times · Source

I am using to check the condition of a thread with if(Thread.IsAlive). A form is running in this thread. At times during execution, even though the form remains open, the call to Thread.IsAlive seems to be evaluating to false. I thought to perform the same check with if(Thread.ThreadState==ThreadState.Running). Is it the right way to do? If not, what is the possible work around?

Answer

WhileTrueSleep picture WhileTrueSleep · Apr 26, 2013

msdn Thread.IsAlive Property true if this thread has been started and has not terminated normally or aborted; otherwise, false.

msdn Thread.ThreadState

  • Running
    The thread has been started, it is not blocked, and there is no pending ThreadAbortException.
  • StopRequested
  • SuspendRequested
  • Background
  • Unstarted
  • WaitSleepJoin
  • Suspended
  • AbortRequested

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