How Can A Thread Be Resumed When Its Current State Is 96?




I'd like to post this as a new thread to an article in
microsoft.public.dotnet.languages.vb originally made by nevin and replied to
by Alan Pretre back in December ("ThreadState == not in the enumeration").

Like nevin, I have a VB.NET multi-threaded application, and quite
frequently, after my main application class will call Thread.Suspend() on the
thread the ThreadState of the Suspended Thread will be a value of 96. From
Alan's reply, this is a bitwise value indicating that the suspended thread is
in a state that is both ThreadState.Suspended And ThreadState.WaitSleepJoin.

In the Command Window, I can execute the following statement and it returns
a value of True when evaluated:

? myThread.ThreadState = 96

However, anytime I attempt to compile and debug with Option Strict and
Option Explicit On, none of the following is executed when running the
application or stepping through the code in debug mode:

If myThread.ThreadState = 96 Then ....

If (myThread.ThreadState And System.Threading.ThreadState.Thread.Suspended)
= System.Threading.ThreadState.Thread.Suspended Then ....

One approach that has been successful for me is to set a boolean variable
within my application class that I use as a flag indicating whehter or not
the thread instance has already been suspended, such as:

' Try-Catch block omitted for clarity...
isMyThreadSuspended = True

.... and to resume....

If isMyThreadSuspended Then
' Try-Catch block omitted for clarity...
isMyThreadSuspended = False
End If

Although feasible for an application with a single thread, having multiple
flags to set and check for each thread instance in an application with
multiple threads that my application class will create doesn't seem correct
to me, especially since System.Threading.Thread.ThreadState is a Read-Only
property, and in terms of functional responsibility, this property should be
able to get and consistently and properly detect the current state of a

With this in mind, can anyone suggest a way to consistently and reliably
check for all suspended thread states, including ThreadState 96 using the
ThreadState property so I can have my application class call
System.Threading.Thread.Resume() on a thread instance with this state?

I'm using Visual Studio.NET 2003 Version 7.1.3088 and have the .NET
Framework 1.1, Version 1.1.4322 SP1.

Any help or insights on this issue would be greatly appreciated.

Thank you in advance for your time and help....

Jay B. Harlow [MVP - Outlook]

First calling Suspend & Resume on threads is not recommended!


Using something like:

If (myThread.ThreadState And ThreadState.Suspended) =
ThreadState.Suspended Then
End If

Should work, at least it should remove the Suspended attribute, but I would
expect the thread to stay in the WaitSleepJoin state.

The following post shows an example of how you can suspend threads without
using Thread.Suspend:

Hope this helps

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question