473,412 Members | 3,471 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,412 software developers and data experts.

Start a thread that is sleeping?

If I use Threading.Thread.Sleep is there a way to cancel that sleep from
another thread?

Regards
Fredrik
Nov 20 '05 #1
3 1152
Cor
Hi Frederik,

As far as I can see you can only let it sleep some time, so you have to let
it sleep.

But I think you can set somewhere a shared boolean from any thread when you
have build a loop in your thread like this.

do while shared_boolean_for_this_thread
thread.sleep(50)
loop

I thought you can set that boolean to false in another thread.
I thought I did somethings like that but not this.

So just a thought never tested.

Cor
Nov 20 '05 #2
Thanks that worked for my problem.

- Fredrik
"Cor" <no*@non.com> wrote in message
news:uI*************@TK2MSFTNGP11.phx.gbl...
Hi Frederik,

As far as I can see you can only let it sleep some time, so you have to let it sleep.

But I think you can set somewhere a shared boolean from any thread when you have build a loop in your thread like this.

do while shared_boolean_for_this_thread
thread.sleep(50)
loop

I thought you can set that boolean to false in another thread.
I thought I did somethings like that but not this.

So just a thought never tested.

Cor

Nov 20 '05 #3
Fredrik,
Not per se.

If you need the ability you should use a WaitHandle, such as AutoResetEvent
or ManualResetEvent.

Then instead of using Threading.Thread.Sleep you would use
Threading.WaitHandle.WaitOne with a timeout value. The other thread can use
*ResetEvent.Set to cause the first thread to wake up. With the timeout on
WaitOne the first thread will automatically wake up if another thread does
not call Set.

Dim event As New AutoResetEvent

Public Sub Tread1()
If event.WaitOne(2000, False) Then
' event.Set was called
Else
' event timed out
End if
End Sub

Public Sub Thread2()
event.Set() ' wake up thread1
End Sub

Hope this helps
Jay

"Fredrik Melin" <me*@n.o.spam.dacsa.net.remove.as.needed> wrote in message
news:b-********************@giganews.com...
If I use Threading.Thread.Sleep is there a way to cancel that sleep from
another thread?

Regards
Fredrik

Nov 20 '05 #4

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...
8
by: Cider123 | last post by:
I ran into a situation where my Window Service had to process 100,000+ files, when I first noticed I needed to tweak various routines. Everything runs fine, but here's what I ran into: In the...
4
by: Matthew Groch | last post by:
Hi all, I've got a server that handles a relatively high number of concurrent transactions (on the magnitude of 1000's per second). Client applications establish socket connections with the...
4
by: cmay | last post by:
Can someone give me some guidance on this? I am implementing a system where if a user fails the login, I am doing a thread.sleep(random number). If I returned the page right away, you could...
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...
0
by: Yue Fei | last post by:
I have a multi thread python code, threads can start immediately if I run on command line, but I can get them started right the way if I call the same code from C/C++. test code like this: from...
2
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I have a thread ABC that starts another thread XYX. Thread XYZ monitors various things and if there is no work to do it calls Thread.Sleep to sleep for a minute or so. Occasionally...
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...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.