Question about ThreadState bitmask and MSDN docs

Hi all freinds
It say in MSDN Doc

"TheThread.ThreadState property of a thread provides the current state of a thread.Applications must use a bitmask to determine whether a thread is running. Since the value forRunning is zero (0), test whether a thread is running by using C# code such as(myThread.ThreadState & (ThreadState.Stopped | ThreadState.Unstarted)) == 0 or Visual Basic code such as(myThread.ThreadState And (ThreadState.Stopped Or ThreadState.Unstarted)) = 0."

My question is, can not I use:

if(myThread.ThreadState == System.Threading.ThreadState.Running)
instead since I have seen it in some books and internet forumes?!

How about getting the bitmask to determine if myThread is "Stopped" and what about the bitmask to determin if a myThread is "Aborted"

Are there any reference to explain these bit mask think clearly in C#?

Thanks a lot

[1316 byte] By [Awsok] at [2007-12-16]
# 1

As ThreadState.Running value is 0, the problem occurs if the Thread is a background thread, in which case if myThread is running, ThreadState would only return ThreadState.Background.

To check Stopped:



if ((myThread.ThreadState & ThreadState.Stopped) == ThreadState.Stopped)
{
// Thread has been stopped
}

To check Aborted:



if ((myThread.ThreadState & ThreadState.Aborted) == ThreadState.Aborted)
{
// Thread has been aborted
}

DavidM.Kean at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified