473,383 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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 2978
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Daylor | last post by:
in win32 process , when u create new process,u have new main thread. i know,appDomain r logical procces,that exists in 1 win32 process. the q: is there way to create second appDomain (the...
31
by: AlexeiOst | last post by:
Everywhere in documentation there are recommendations to use threads from thread pooling for relatively short tasks. As I understand, fetching a page or multiple pages (sometimes up to 50 but not...
7
by: mike | last post by:
Hi, I am having difficulty in creating a thread using pthread_create. It seems that pthread_create does not execute 'program', and returns -1; I have checked the API but I am not sure why this...
6
by: RickDee | last post by:
Understand that when I start a thread, a number will be generated and is able to get from GetHashCode method. But I would like to use this number when I want to kill certain thread, anybody know...
1
by: Amratash | last post by:
I'm receiving the above mentioned error.The problem is: "I suspend one thread.Another thread is resuming the first thread.Then I added following code:Its in simple english if(first thread is not...
2
by: Mark Denardo | last post by:
I'm trying to abort a suspended thread, but I get a ThreadStateException: An unhandled exception of type 'System.Threading.ThreadStateException' occurred in mscorlib.dll Additional...
1
by: JEB | last post by:
I know that with Web Services, you should be doing everything in a stateless environment. However, I have three methods out of over 100 that need state. I have the client cookie container,...
5
by: Alan T | last post by:
I will do several things in my thread: Copy a file to a location Update database record Read the file content Write the content to a log file If I call Thread.Abort(), it may be possible to...
3
by: stumorgan | last post by:
Basically what I have is a form with a graph on it which graphs data that I'm reading from a USB device at 100 Hz (every 10ms). I have a thread reading and parsing the data from the USB, but when...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.