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

785 questions
433
votes
7 answers

How do I make a delay in Java?

I am trying to do something in Java and I need something to wait / delay for an amount of seconds in a while loop. while (true) { if (i == 3) { i = 0; } ceva[i].setSelected(true); // I need to wait here …
ardb
  • 4,655
  • 5
  • 12
  • 15
70
votes
3 answers

Why there is a Thread.Sleep(1) in .NET internal Hashtable?

Recently I was reading implementation of .NET Hashtable and encountered piece of code that I don't understand. Part of the code is: int num3 = 0; int num4; do { num4 = this.version; bucket = bucketArray[index]; if (++num3 % 8 == 0) …
Dariusz Woźniak
  • 8,073
  • 5
  • 48
  • 67
37
votes
1 answer

How to put delay before doing an operation in WPF

I tried to use the below code to make a 2 second delay before navigating to the next window. But the thread is invoking first and the textblock gets displayed for a microsecond and landed into the next page. I heard a dispatcher would do that. Here…
BharathNadadur
  • 457
  • 1
  • 6
  • 13
30
votes
6 answers

How to suspend a java thread for a small period of time, like 100 nanoseconds?

I know Thread.sleep() can make a java thread suspend for a while, like certain milliseconds and certain nanoseconds. But the problem is the invocation of this function also causes overhead. For example, if I want a thread to suspend for 100…
JackWM
  • 8,835
  • 18
  • 58
  • 90
27
votes
4 answers

Thread.sleep() VS Executor.scheduleWithFixedDelay()

Goal: Execute certain code every once in a while. Question: In terms of performance, is there a significant difference between: while(true) { execute(); Thread.sleep(10 * 1000); } and executor.scheduleWithFixedDelay(runnableWithoutSleep, 0,…
25
votes
3 answers

Stopping long-sleep threads

Let's suppose I have a thread which should perform some task periodically but this period is 6 times each hour 12 times each hour (every 5 minutes), I've often seen code which controls the thread loop with a is_running flag which is checked every…
PaperBirdMaster
  • 11,602
  • 9
  • 41
  • 84
24
votes
4 answers

Android sleep() without blocking UI

For my new Android application I need a function, that timeout my application for 3 Seconds. I tried the function "sleep()" like this: seekBar1.setProgress(50); // Set something for my SeekBar try{ Thread.sleep(3000); …
Pascal
  • 1,055
  • 4
  • 17
  • 42
22
votes
2 answers

Making a Thread to Sleep for 30 minutes

I want to make my thread to wait for 30 minutes. Are there any problems of doing this?
venkata lokesh
  • 249
  • 1
  • 2
  • 3
20
votes
3 answers

Alternatives to using Thread.Sleep for waiting

Firstly I am not asking the same question as C# - Alternative to Thread.Sleep?, or Alternative to Thread.Sleep in C#?. I don't think I am using it incorrectly and need a genuine alternative for specific situations. During a code analysis run I saw a…
BrutalDev
  • 5,978
  • 6
  • 55
  • 65
19
votes
2 answers

android game loop vs updating in the rendering thread

I'm making an android game and am currently not getting the performance I'd like. I have a game loop in its own thread which updates an object's position. The rendering thread will traverse these objects and draw them. The current behavior is what…
user1578101
  • 205
  • 1
  • 2
  • 6
17
votes
2 answers

Sleep function in android program

Having some problem getting my program to sleep What im trying to do is when the btnStart is pressed firs randomly set pictures to 12 ImageButtons Then i want it to pause for 5 secs and then change the first ImageButton to another picture My code…
Fredkr
  • 714
  • 2
  • 8
  • 20
16
votes
4 answers

Android Sleep/Wait/Delay function

first of all, I'm a beginner to android world so please apologize me if it is stupid question.. I'm trying to do following: Enable Mobile Data Wait for 10 seconds a. check if Mobile got IP address (data connected sucessfully) b. if Not…
ShitalSavekar
  • 277
  • 2
  • 4
  • 10
15
votes
3 answers

std::this_thread::sleep_for() and nanoseconds

If I put two calls side-by-side to determine the smallest measurable time duration: // g++ -std=c++11 -O3 -Wall test.cpp #include typedef std::chrono::high_resolution_clock hrc; hrc::time_point start = hrc::now(); hrc::time_point end =…
Stéphane
  • 17,613
  • 22
  • 82
  • 117
14
votes
5 answers

Thread sleep/wait until a new day

I'm running a process in a loop which has a limit on the number of operations it does per day. When it reaches this limit I've currently got it checking the the time in a loop to see if it a new date. Would the best option be to: Keep checking the…
finoutlook
  • 2,393
  • 5
  • 26
  • 42
14
votes
3 answers

Sleeping less than a second in OCaml

The Unix.sleep function can suspend the program for whole seconds, but how can you suspend it for less than a second?
Matthew Piziak
  • 3,185
  • 4
  • 28
  • 46
1
2 3
52 53