473,396 Members | 2,154 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,396 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 21093
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.