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
7
votes
1 answer

Java Thread.sleep for minimum time

The TimeUnit.sleep(long timeout) documentation describes its argument thus: timeout - the minimum time to sleep. However, I'm finding that — at least on Windows 7 64-bit with Java 8 update 141 — the thread often sleeps for less than the…
Klitos Kyriacou
  • 10,634
  • 2
  • 38
  • 70
7
votes
2 answers

Thread sleep and precise timing

I am making a code where I want definite precision in my timing. I use a robot to make some actions, then I use Thread.sleep(some_time) for some_time to be elapsed between the actions. But I don't get best results because as I search it, sleep is…
user3265784
7
votes
3 answers

Call Thread.Sleep from the Task

Is it correct to use Thread.Sleep() inside the task. Or is only a timer (Task.Delay() in .Net 4.5 and latter) used with task? Or maybe another approaches exist.
SerG
  • 1,251
  • 4
  • 18
  • 37
7
votes
1 answer

How JavaFX application thread works?

I have a problem with Java FX application thread. Here is a pseudo-code: showMenu(); //Contoller which waits for action(pressing button)... showLoadingPic(); Thread.sleep(2000); showMap(); The problem is that the sleep occurs in window which is…
ulzhan
  • 143
  • 2
  • 2
  • 6
7
votes
5 answers

TcpClient.Close() works only with Thread.Sleep()

I have simple server that gets string from client and prints it on screen. I also have simple client, sending data and closing: static void Main() { var client = new TcpClient("localhost", 26140); var stream = client.GetStream(); …
VorobeY1326
  • 782
  • 10
  • 25
7
votes
3 answers

Bound the runtime of a computation in haskell

I'm writing a game AI in Haskell, and I want to search the game state tree for a specified amount of time (i.e. I always want to AI to take 3 seconds to make its decision on what move to make) How can I do this in a pure language like Haskell? I…
Drew
  • 12,578
  • 11
  • 58
  • 98
7
votes
2 answers

Thread and battery consumption

I am working on app that check some of the status of phone every 5 seconds. I done it that: Thread checking = new Thread() { public void run(){ while( <> ) { <> …
Mateusz Kaflowski
  • 2,221
  • 1
  • 29
  • 35
7
votes
2 answers

Access Thread from inside Runnable

How can I access Thread object that is executing given Runnable? What I'd like to do is to call sleep() from within run() method.
alex
  • 10,900
  • 15
  • 70
  • 100
6
votes
6 answers

Problems with using Thread.Sleep for short times

I have an app with 2 threads (now), but it seems that function Thread.Sleep() doesn't work very good. It sleeps threads but it takes much more time (for example- I want to sleep it for 5ms and it sleeps for 0,3s or more). Here is code: int vlakien =…
matej148
  • 155
  • 1
  • 13
6
votes
5 answers

How to get rid of this "static method should be acessed in a static way" in java?

I have the following piece of code in a java application Thread.currentThread().sleep(10000); However eclipse is showing me the following warning: The static method sleep(long) from the type Thread should be accessed in a static way I am very…
Victor
  • 1,655
  • 9
  • 26
  • 38
6
votes
1 answer

Rust lang thread::sleep() sleeping for almost twice the specified time during game loop on windows

So I've written the following function to show what i mean: use std::{thread, time}; const TARGET_FPS: u64 = 60; fn main() { let mut frames = 0; let target_ft = time::Duration::from_micros(1000000 / TARGET_FPS); println!("target frame…
user11165129
6
votes
1 answer

forceLayout(), requestLayout()

My reading of the android documentation finds the methods forceLayout() (which is to produce a layout display at the next layout request) and requestLayout() (which is supposed to post an immediate layout request), but I can not get them to behave…
peter gottlieb
  • 441
  • 2
  • 5
  • 9
6
votes
4 answers

How to write in multiple positions in a console application at the same time? C#

I want lines as many as the width of the console to simultaneously write downwards one char to the height of the console. I've done most of it, but it goes from top to bottom to right etc... If you need help picturing what I mean, think of the…
sweetroll
  • 331
  • 3
  • 12
6
votes
1 answer

How to avoid 100% CPU in Delphi multithreading?

I am creating a mechanism for sending and receiving data on multiple servers. Servers are run on Windows and Delphi 7 is used. Sending data is formed in several simultaneous threads and it is not possible to know which thread will form the data…
6
votes
1 answer

Should I always use Task.Delay instead of Thread.Sleep?

I have recently seen several recommendations stating that Thread.Sleep should never be used in production code (most recently in this SO question). Many of these advocate for using Task.Delay instead. Most of the explanations I've found use UI…
BJ Myers
  • 6,617
  • 6
  • 34
  • 50