473,386 Members | 1,758 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,386 software developers and data experts.

How to wake up a sleeping thread?

Hello,

I have a thread that in the middle of the execution I did Thread.Sleep().
How do I tell this thread to abort it sleep and continues? Is there a way?

thanks,

/m
Nov 15 '05 #1
4 21089
Use Suspend() instead of Sleep(), then use Resume().

Jon
"Muscha" <mu****@no.spam.net> wrote in message
news:On**************@TK2MSFTNGP09.phx.gbl...
Hello,

I have a thread that in the middle of the execution I did Thread.Sleep().
How do I tell this thread to abort it sleep and continues? Is there a way?

thanks,

/m

Nov 15 '05 #2
> Use Suspend() instead of Sleep(), then use Resume().

However Suspend() does no take the parameter how long should I suspend it
for. In this case I need to setup another thread just to resume this
suspended thread.

/m

Jon
"Muscha" <mu****@no.spam.net> wrote in message
news:On**************@TK2MSFTNGP09.phx.gbl...
Hello,

I have a thread that in the middle of the execution I did Thread.Sleep(). How do I tell this thread to abort it sleep and continues? Is there a way?
thanks,

/m


Nov 15 '05 #3
I suggest that you look at the WaitHandle class, where you can use, perhaps,
WaitOne( int millisecondsTimeout, bool exitContext )
Then to interrupt it before the timeout, you'd use the Set method in one of
the derived, instantiable classes, such as AutoResetEvent.
You can check the return value of WaitOne to determine if it was a timeout
or an event.

Hope this helps,
Chris R.
"Muscha" <mu****@no.spam.net> wrote in message
news:On**************@TK2MSFTNGP09.phx.gbl...
Hello,

I have a thread that in the middle of the execution I did Thread.Sleep().
How do I tell this thread to abort it sleep and continues? Is there a way?

thanks,

/m

Nov 15 '05 #4
Hi,

You might use Monitor instead.
From the thread call Monitor.Wait (object that becomes locked, TimeSpan)
From the other thread call Monitor.Pulse to awake the waiting thread.

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com

"Muscha" <mu****@no.spam.net> wrote in message
news:eW**************@TK2MSFTNGP10.phx.gbl...
Use Suspend() instead of Sleep(), then use Resume().


However Suspend() does no take the parameter how long should I suspend it
for. In this case I need to setup another thread just to resume this
suspended thread.

/m

Jon
"Muscha" <mu****@no.spam.net> wrote in message
news:On**************@TK2MSFTNGP09.phx.gbl...
Hello,

I have a thread that in the middle of the execution I did Thread.Sleep(). How do I tell this thread to abort it sleep and continues? Is there a way?
thanks,

/m



Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: COMfused | last post by:
I have a thread that has a delegate function which will be called when another process exits. This thread went to sleep, the process exits and is supposed to call the delegate, but it did not...
16
by: Alvin Bruney | last post by:
I'm observing that a sleeping thread changes to stopped after a while. Is that accepted framework behavior for web applications? My thread basically does some work, and sleeps for 60 minutes...
2
by: Scott M. Lyon | last post by:
I've got an application that, in the main form, Starts up a thread. That thread consists of an endless loop (a WHILE TRUE loop), at the end of each iteration is a Sleep() command, so it will sleep...
17
by: Benny Raymond | last post by:
I have a thread that sleeps for 5 minutes once it's finished running a method and then it repeats itself if it's supposed to (bool = true). Prior to 2.0 I was able to resume the thread after...
2
by: Mark | last post by:
We are building a public web application that calls a web service on an internal box. The web service runs for 5-10 minutes, does some heavy processing, and writes to a database when it is...
3
by: ercastro | last post by:
I am a new user of Visual Basic. I am currently using VB 2005. I am running a time-consuming task on the built-in BackgroundWorker() control of VB. I am using nested loops and sometimes I need...
0
by: Buckaroo Banzai | last post by:
Hello, newbie here... I'm writing this program but when I click the start button which should initiate either the Hare or the Tortoise, it does not, this is the first time I use threads, so the...
18
by: J.K. Baltzersen | last post by:
To whomever it may concern: I am using MS Visual C++ 6.0. I have a process A which instantiates an object C. At a later point the process A creates the thread B. The thread B has access...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.