0

hey guys,

I need this

Var1 = 0;
Sleep(500);
Var1 = 1;

My problem is that the Sleep makes all my threads sleep.

I want only the one thread I'm in sleep.

Thanks,

Jeff

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by chiwawa10
0

Sleep() only works for the current thread, it does not affect other threads. So if you think other threads are also sleeping then you are doing something wrong or you do not understand the code you wrote.

If you put that same Sleep() at the same place in the code for each thread then each of them may sleep at the same time and confuse you, the programmer. If that is the case, then maybe call Sleep() with a different parameter value for each thread so that they are not all simultaneously sleeping for the same amount of time.

0

Based on the code posted, I assume that it is running on the main thread. Calling Sleep() from the main thread causes the program to pause for the specific amount of time. All others background threads will still be running and doing some work.
If you need some background work to be done while the current(main) thread is sleeping, try to spawn a background thread. More code is needed to analyze what is happening in your case.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.