sleep

Delay execution 1 second

倾然丶 夕夏残阳落幕 提交于 2019-12-29 08:42:04
问题 So I am trying to program a simple tick-based game. I write in C++ on a linux machine. The code below illustrates what I'm trying to accomplish. for (unsigned int i = 0; i < 40; ++i) { functioncall(); sleep(1000); // wait 1 second for the next function call } Well, this doesn't work. It seems that it sleeps for 40 seconds, then prints out whatever the result is from the function call. I also tried creating a new function called delay, and it looked like this: void delay(int seconds) { time_t

Thread sleep and precise timing [duplicate]

不羁的心 提交于 2019-12-29 06:54:09
问题 This question already has answers here : How accurate is Thread.sleep? (3 answers) Closed 3 years ago . 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 not accurate. What would be the best way to accomplish this? I mean simulate Thread.sleep with other methods. 回答1: Timing in modern OSes is never

Detect Gesture with Phone sleeping [closed]

风格不统一 提交于 2019-12-29 06:37:27
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . I am developing an SOS android app. I want to detect a gesture (for example several touches on screen) if the phone is in mode sleep/standby, and start a send of help request (for example send a sms). How can I detect this gesture? Someone that can help me? Thank you ---SOLUTION--

To make a choice between ManualResetEvent or Thread.Sleep()

房东的猫 提交于 2019-12-29 05:25:17
问题 I am not sure which strategy to adopt...I am focusing on my operation getting completed, but I'd also like to keep performance issues to a min too...there is a method called Execute() which has to wait (run synchronously) until an operation completes. This operation happens on another thread. There are 2 ways to implement the same thing... By using ManualResetEvent void Execute() { taskHandle = new ManualResetEvent(false); . . //delegate task to another thread . . taskHandle.WaitOne(); } OR

How can I stop PHP sleep() affecting my whole PHP code?

本小妞迷上赌 提交于 2019-12-28 03:04:07
问题 So, on my arcade, howlingdoggames.com. I have a points system that gives you a point every time you visit a page with a game on, now, to reduce abuse of this, I would like to make some sort of delay, so its only awarded after 45 seconds. Here's what i've tried. ... if ($_SESSION['lastgame'] != $gameid);{ sleep(45); $points = $points + $game_points; $_SESSION['lastgame'] = $gameid; } ... But, this just seems to halt my whole website for 45 seconds, because this is in the index.php file, as

sleep and usleep start wrong

戏子无情 提交于 2019-12-26 09:16:37
问题 In C++ I use usleep in my "main" path and call the function out before. out(); usleep(4000000); out just prints something on the screen. Unfortunately the print appears on the screen only after 4 seconds, though the out() function call is before the usleep command. I work on a raspberry with raspbian. How can it be that not first the function out() ; is called and then usleep starts but the other way round? 回答1: In C++ in order to decrease the time of IO we have buffered output. What that

Identify Special key keycode

馋奶兔 提交于 2019-12-25 16:59:17
问题 I am using a windows 8 laptop. My old laptop had a key combo, fn+f5, which would make the computer go to sleep. My new laptop has a power button on the side that acts like the one on your phone, it puts the PC to standby/sleep. But i don't like hardware buttons because they wear out. I plugged in a logitech keyboard that has a dedicated key with the power button symbol and when you press it, it does the same thing. (i did not install any software or drivers btw, just plugged it in) My goal is

How to sleep/pause in Qt? [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-12-25 11:53:46
问题 This question already has answers here : Substitute for sleep function in Qt/C++ (3 answers) Closed 5 years ago . How do I "Sleep/Pause" inside Qt. I want the UI to remain responsive while the code is sleeping. while(Tablet.IsConnected() == false){ LogText("[Prep] Tablet not turned back on... Retrying..."); //Sleep for three seconds here } LogText("[Prep] Tablet Detected!"); 回答1: let tablet emit a signal: in your constructor you will then do: connect(Tablet, SIGNAL(connected()), this, SLOT

How to simultaneously display a splash screen and then my JFrame?

冷暖自知 提交于 2019-12-25 08:04:00
问题 I am working on a splash screen. I managed to make a class. Below is a class that displays a splash screen. My problem is If I call this class from a JFrame and run, both JFrame and Splash screen runs at the same time and after the duration the splash screen is supposed to last Both of them is closed. How to I make them display simultaneously ? Thanks a bunch public class Splash extends JWindow { AbsoluteLayout abs; AbsoluteConstraints absImage, absBar; ImageIcon image; JLabel label;

Thread.sleep() in while loop doesn't work properly?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 07:59:43
问题 The object is supposed to change modes (movement algorithm) every 5 seconds. I first tried with a while loop but the loop was iterating way too fast. Then I added Thread.sleep(5000) but still my object moves only in one algorithm ( scatterMode ). Here is the algorithm: //LEVEL 1 //scatter for 7s //chase for 20s //scatter for 7s //chase for 20s //scatter for 5s //chase for 20s //scatter for 5s //chase indefinite And here is the code. The constructor and variable declarations are at the bottom