Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

60 views
Skip to first unread message

alundi

unread,
Jan 30, 2005, 2:17:01 PM1/30/05
to
Greetings:

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...
'
myThread.Suspend()
isMyThreadSuspended = True

... and to resume....

If isMyThreadSuspended Then
'
' Try-Catch block omitted for clarity...
'
myThread.Resume()
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
thread.

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]

unread,
Jan 30, 2005, 2:52:22 PM1/30/05
to
alundi,
First calling Suspend & Resume on threads is not recommended!

See CAUTION at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemthreadingthreadclasssuspendtopic.asp

Using something like:

If (myThread.ThreadState And ThreadState.Suspended) =
ThreadState.Suspended Then
myThread.Resume
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:

http://groups-beta.google.com/group/microsoft.public.dotnet.languages.vb/browse_thread/thread/ddfcb3c82319ccea/ef1c8ac5e2172968?q=thread.suspend+jay&_done=%2Fgroups%3Fq%3Dthread.suspend+jay%26&_doneTitle=Back+to+Search&&d#ef1c8ac5e2172968

Hope this helps
Jay

"alundi" <alu...@discussions.microsoft.com> wrote in message
news:EDC5E2DB-8281-4805...@microsoft.com...

0 new messages