Find out if a Thread was stopped via Suspend

  • Thread starter Thread starter Ford Prefect alias Armin
  • Start date Start date
F

Ford Prefect alias Armin

I want to start a Thread and wait till the Thread has been stopped (via
Suspend)

How to do this.

Sub Test

Start Thread
Wait Till Stopped
Go on with this code as sone as the Thread has stopped.

End Sub

I know it looks like "Why does he use threads for this ?" but I need it that
way...
 
what does this tell you when the thread is stopped?

Thread.CurrentThread.IsAlive()
OHM#

I want to start a Thread and wait till the Thread has been stopped
(via Suspend)

How to do this.

Sub Test

Start Thread
Wait Till Stopped
Go on with this code as sone as the Thread has stopped.

End Sub

I know it looks like "Why does he use threads for this ?" but I need
it that way...

Regards - OHM# (e-mail address removed)
 
* "Ford Prefect alias Armin said:
I want to start a Thread and wait till the Thread has been stopped (via
Suspend)

Maybe with the thread's 'ThreadState' property or 'IsAlive' property.
 
If you want to wait until the thread has finished, use Thread.Join. Waiting
until it has been suspended is slightly more difficult.

If the thread only suspends itself, use an "AutoResetEvent" object to signal
the waiting thread that it has been suspended. However, if any other thread
can suspend it, use a loop in your main thread and check the "ThreadState"
property of the thread you're watching.

e.g.


Sub Test

Start Thread

do until (Thread.ThreadState = Suspended) orelse (Thread.ThreadState =
Stopped)
Sleep my thread to release processer in the loop
loop

Go on with this code as soon as the Thread has stopped.

End Sub


There are better ways of doing this (e.g. using Reset Events and other
signalling methods), but they involve a little bit more code than this
example.

Hope this helps,

Trev.
 
Thanx :-)

I want to do this:

if I use Thread.CurrentThread.IsAlive then I have to do a do .. loop or
something because I do not want that the Code is going on untill the Thread
is
stopped.

What can I do to not use a do loop (because then my whole machine is
blocked....)


The Problem is that I wanted to do some kind of interaction in Web.

In Web the Code runs on the Server.

So If you need Input from the Client you always have to go back to the
Client.


The started Thread calls a DLL of a User which uses our API Function.
The User call a function from our DLL.
This function returns a Inoput from the Client Side........

I have to possibilities to do this.

The easy one:

Using Events.

But then the Logic of the User DLL has to be cut in to parts.

The luxourious one:

Running the UserDLL Sub as a Thread.
Then the Developer User calling our API Function (GetMeInputfromTheUser)
If in the API Funtion I abort the Thread.
Now the Routine that started the thread should go one with running
and get back to the client.

The Client makes the input, sends it back to the server.
I continue the Thread give the UserDLL the Input
and the User DLL rubns on with it's code.


An easier way where to do it without threads and
make some kind of Child request to the Client.....
But I don't know how to do this and somebody tells me this is not
possible.....
 
To let main Thread spleeping in the Loop is a good idea !!!

It's not a good idea - it's a lazy one ;)

If you have a bit of time on your hands, read up a bit more on thread
synchronization techniques (Monitors, Auto and Manual Reset Events etc.).
It'll not only give you a better understanding of threading, but it will
make your code a bit more robust and efficient than a simple loop.

Here's some links that may be of use to you:
http://msdn.microsoft.com/library/d...n-us/vbcn7/html/vaconFreeThreadingExample.asp
http://msdn.microsoft.com/library/d...-us/vbcn7/html/vaconthreadsynchronization.asp

Hope this helps,

Trev.
 
Hi Armin (Ford Prefect)
I want to start a Thread and wait till the Thread has been stopped (via
Suspend)

What is the reason for starting a thread and really totaly stop the main
thread?

That gives only slower performance and no goals at all.

It makes me curious.

Cor
 
Back
Top