Questions tagged [thread-sleep]

The .net Thread.Sleep(...) method suspends the caller for a specified amount of time.

A call to Thread.Sleep(n) has no side effects, and it will not return until at least n milliseconds have elapsed.

References

815 questions
11
votes
3 answers

make PHP wait until a function completes?

Is there any way to make PHP wait until a function returns before continuing? This is my code:
markasoftware
  • 12,292
  • 8
  • 41
  • 69
10
votes
5 answers

Can I improve the resolution of Thread.Sleep?

Thread.Sleep() resolution varies from 1 to 15.6ms Given this console app: class Program { static void Main() { int outer = 100; int inner = 100; Stopwatch sw = new Stopwatch(); for (int j = 0; j < outer;…
Igby Largeman
  • 16,495
  • 3
  • 60
  • 86
10
votes
4 answers

How to create a delay in Swing

I made a blackjack game, and I want the AI player to pause between taking cards. I tried simply using Thread.sleep(x), but that makes it freeze until the AI player is done taking all of his cards. I know that Swing is not thread safe, so I looked at…
Fractaly
  • 834
  • 2
  • 10
  • 25
10
votes
3 answers

Does Thread.Sleep hinder other threads?

Here is a console program want 10 threads start in batch, wait 5 seconds, and stop in batch. static void Main(string[] args) { System.Threading.Tasks.Parallel.For(0, 10, (index) => { Action act = (i) => { …
demaxSH
  • 1,743
  • 2
  • 20
  • 27
10
votes
2 answers

Can std::this_thread::sleep_for() have spurious wakeups?

Note, this is not a question about std::condition_variable::wait_for(). I know that can wake spuriously. My program’s behavior suggests the answer to this question is Yes, but the STL documentation is quite clear for the condition_variable case. At…
Andrew Lazarus
  • 18,205
  • 3
  • 35
  • 53
10
votes
3 answers

abortable sleep() in Python

I need a sleep() method which can be aborted (as described here or here). My approach is to let a threading.Event.wait() timeout at the specified duration: def abortable_sleep(secs, abort_event): abort_event.wait(timeout=secs) …
frans
  • 8,868
  • 11
  • 58
  • 132
10
votes
5 answers

Thread.Sleep(0) doesn't work as described?

I am currently reading this excellent article on threading and read the following text: Thread.Sleep(0) relinquishes the thread’s current time slice immediately, voluntarily handing over the CPU to other threads. I wanted to test this and below is…
Jordy
  • 1,816
  • 16
  • 29
9
votes
7 answers

How can we make a thread to sleep for a infinite time in java?

Pls help me to understand how can we make a thread to sleep for a infinite time period .
Logesh
  • 151
  • 1
  • 1
  • 4
8
votes
6 answers

Sleep in loop when application is running, but sleeps too few

private static void Main(string[] args) { for (;;) { TemporaryCityTool.TemporaryCityTool.AddCity(); Console.WriteLine("waiting..."); Thread.Sleep(3600); } } why Thread.sleep not working. I am getting message…
senzacionale
  • 20,448
  • 67
  • 204
  • 316
8
votes
6 answers

Java Wake Sleeping Thread

I did some reading of other post but didn't find an exact answer to what I'm looking for, so I hope someone can give some some clarification. I have a program that will run for some time. I have some threads that run in the back ground that perform…
James Oravec
  • 19,579
  • 27
  • 94
  • 160
8
votes
2 answers

How to "wait" without blocking (busy wait) in JavaScript?

Hi I'm a Javascript Newbie. I've programmed a script which auto types a phrase on a page, pauses for a while, clears the div, auto types the next phrase and so on. It should continuously loop. I've found an issue when using a JavaScript wait()…
user1496306
7
votes
3 answers

How can I pause a Thread for some seconds in Godot?

How can I pause execution for a certain amount of time in Godot? I can't really find a clear answer.
MomoVR
  • 113
  • 1
  • 8
7
votes
3 answers

why c++11 sleep_for microseconds actually sleep for millisecond?

I call this function in my centos 7 server. I find std::this_thread::sleep_for(chrono::nanoseconds(1)) actually sleep for one ms, Is there any explanation? I think it may be caused by os setting?
nick huang
  • 443
  • 4
  • 12
7
votes
1 answer

Jenkins hangs between build and post-build

After updating Jenkins to version 2.156 (from version 1.6), some of our build jobs get stuck after completing and before moving to post-build action. Job itself is finished within 5 minutes (same as before), then it hangs for 5-10 minutes before…
7
votes
2 answers

Sleep() vs sleep_for()

Can someone explain the difference in behavior between these two ways of stopping a thread and then continue it again?. Sleep(); //from Win32 std::this_thread::sleep_for(); I remark in terms of multithreading behavior not in systems…
user8554358
1 2
3
54 55