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

How do I put to sleep a thread other than the current one.

How do I put to sleep a thread other than the current one?

I want to put another thread to sleep to the specified number of
milliseconds but the Sleep method seems to only work for the current thread
while the Suspend method has no parameters to specify a duration.
Nov 15 '05 #1
3 2864
> I want to put another thread to sleep to the specified number of
milliseconds but the Sleep method seems to only work for the current thread while the Suspend method has no parameters to specify a duration.


I am afraid that this is not possible at all. for the thread to sleep it
must be active at the moment you invoke the sleep function (otherwise it is
senseless because the thead IS sleeping!).

what you want to do is not to call Sleep for the other thread but rather to
block its execution for some time. to accomplish that you should use any
object that can synchronize threads, for example Mutexes.

Regards,
Wiktor Zychla
Nov 15 '05 #2
> I am afraid that this is not possible at all. for the thread to sleep it
must be active at the moment you invoke the sleep function (otherwise it is senseless because the thead IS sleeping!).


What if I have a dual processor? Can't processor 1 and 2 be running a
different thread at the same time?

Nov 15 '05 #3
"Rene" <no****@nospam.com> wrote in message
news:O5**************@tk2msftngp13.phx.gbl...
I am afraid that this is not possible at all. for the thread to sleep it
must be active at the moment you invoke the sleep function (otherwise it

is
senseless because the thead IS sleeping!).


What if I have a dual processor? Can't processor 1 and 2 be running a
different thread at the same time?

Sure, but you still need to use the correct synchronization mechanism. In
almost all cases you should use a sync object, e.g. ManualResetEvent, and
the thread blocks on that object until some other thread sets the object to
the signalled state, rather then directly Suspend/Resume a thread.
Nov 15 '05 #4

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

Similar topics

5
by: Anks | last post by:
hi I am displaying a digital clock in an applet.I am using Thread.sleep (1000) for counting every second.This works fine some times but some times my clock just slows down or give an...
1
by: Uri | last post by:
I would like to describe the following scenario: 1. Start a thread which write something to the screen every 5 seconds (the thread uses the sleep method by Thread). current Windows time is...
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...
9
by: Chris Dunaway | last post by:
According to the docs, calling Thread.Sleep(0) causes the thread to be "suspended to allow other waiting threads to execute." What happens if I call Thread.Sleep(500)? Do other threads not get a...
14
by: Joe | last post by:
Does anyone know the difference, in practical terms, between Thread.Sleep (10000) and Thread.CurrentThread.Join (10000)?? The MSDN says that with Join, standard COM and SendMessage pumping...
17
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
11
by: mark | last post by:
Right now I have a thread that sleeps for sometime and check if an event has happened and go back to sleep. Now instead I want the thread to sleep until the event has occured process the event and...
4
by: Frankie | last post by:
This is from MSDN online (http://msdn2.microsoft.com/en-us/library/d00bd51t.aspx): "Specify zero (0) to indicate that this thread should be suspended to allow other waiting threads to execute." ...
13
by: Charles Zhang | last post by:
Sleep() function Sleep at lease 1 millisecond, there is a way to make a thread to sleep less than a millisecond? One way I know of is using performance counter which is not really sleep ( loop and...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.