469,889 Members | 1,416 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,889 developers. It's quick & easy.

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

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....

Nov 21 '05 #1
1 2862
alundi,
First calling Suspend & Resume on threads is not recommended!

See CAUTION at:
http://msdn.microsoft.com/library/de...spendtopic.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/...1c8ac5e2172968

Hope this helps
Jay

"alundi" <al****@discussions.microsoft.com> wrote in message
news:ED**********************************@microsof t.com...
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....

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

31 posts views Thread by AlexeiOst | last post: by
7 posts views Thread by mike | last post: by
6 posts views Thread by RickDee | last post: by
2 posts views Thread by Mark Denardo | last post: by
5 posts views Thread by Alan T | last post: by
3 posts views Thread by stumorgan | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.