By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,812 Members | 1,324 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,812 IT Pros & Developers. It's quick & easy.

Find out if a Thread was stopped via Suspend

P: n/a


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


Nov 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
what does this tell you when the thread is stopped?

Thread.CurrentThread.IsAlive()
OHM#
Ford Prefect alias Armin wrote:
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# On**********@BTInternet.com
Nov 20 '05 #2

P: n/a
* "Ford Prefect alias Armin" <Ar***@humsoft.com> scripsit:
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.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3

P: n/a
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.

"Ford Prefect alias Armin" <Ar***@humsoft.com> wrote in message
news:bq*************@news.t-online.com...


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

Nov 20 '05 #4

P: n/a
Thanx :-)

I want to do this:
Sub Test

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

End Sub

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

"One Handed Man [ OHM ]" <te***************************@BTOpenworld.com>
schrieb im Newsbeitrag news:%2****************@TK2MSFTNGP11.phx.gbl... what does this tell you when the thread is stopped?

Thread.CurrentThread.IsAlive()
OHM#
Ford Prefect alias Armin wrote:
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# On**********@BTInternet.com


Nov 20 '05 #5

P: n/a

To let main Thread spleeping in the Loop is a good idea !!!

Thanx :-)
"Codemonkey" <hu*********@hotmail.com> schrieb im Newsbeitrag
news:%2***************@tk2msftngp13.phx.gbl...
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.

"Ford Prefect alias Armin" <Ar***@humsoft.com> wrote in message
news:bq*************@news.t-online.com...


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


Nov 20 '05 #6

P: n/a
> 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/de...ingExample.asp
http://msdn.microsoft.com/library/de...ronization.asp

Hope this helps,

Trev.
"Ford Prefect alias Armin" <Ar***@humsoft.com> wrote in message
news:bq*************@news.t-online.com...

To let main Thread spleeping in the Loop is a good idea !!!

Thanx :-)
"Codemonkey" <hu*********@hotmail.com> schrieb im Newsbeitrag
news:%2***************@tk2msftngp13.phx.gbl...
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.

"Ford Prefect alias Armin" <Ar***@humsoft.com> wrote in message
news:bq*************@news.t-online.com...


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



Nov 20 '05 #7

P: n/a
Cor
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
Nov 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.