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

Recommended Answers

All 2 Replies

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.