sleep

How to reveal that screen is locked?

混江龙づ霸主 提交于 2019-11-29 00:01:47
问题 In my application I need to know when device is locked (on HTC's it looks like short press on "power" button). So the question is: which event is triggered when device is locked? Or device is going to sleep? 回答1: You should extend BroadcastReceiver and implement onReceive , like this: public class YourBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (Intent.ACTION_SCREEN_OFF.equalsIgnoreCase(intent.getAction())) { //screen has

How do you make a program sleep in C++ on Win 32?

醉酒当歌 提交于 2019-11-28 23:21:35
How does one "pause" a program in C++ on Win 32, and what libraries must be included? #include <windows.h> Sleep(number of milliseconds); Or if you want to pause your program while waiting for another program, use WaitForSingleObject . If you are using boost, you can use the thread::sleep function: #include <boost/thread/thread.hpp> boost::system_time time = boost::get_system_time(); time += boost::posix_time::seconds(1); boost::thread::sleep(time); Otherwise, you are going to have to use the win32 api: #include <windows.h> Sleep(1000); And, apparently, C++0x includes this: #include <thread>

What is the difference between Thread.Sleep(timeout) and ManualResetEvent.Wait(timeout)?

一曲冷凌霜 提交于 2019-11-28 20:49:05
Both Thread.Sleep(timeout) and resetEvent.Wait(timeout) cause execution to pause for at least timeout milliseconds, so is there a difference between them? I know that Thread.Sleep causes the thread to give up the remainder of its time slice, thus possibly resulting in a sleep that lasts far longer than asked for. Does the Wait(timeout) method of a ManualResetEvent object have the same problem? Edit : I'm aware that a ManualResetEvent's main point is to be signaled from another thread - right now I'm only concerned with the case of an event's Wait method with a timeout specified, and no other

Cross platform Sleep function for C++

江枫思渺然 提交于 2019-11-28 18:36:42
Is it possible with macros make cross platform Sleep code? For example #ifdef LINUX #include <header_for_linux_sleep_function.h> #endif #ifdef WINDOWS #include <header_for_windows_sleep_function.h> #endif ... Sleep(miliseconds); ... shf301 Yes there is. What you do is wrap the different system sleeps calls in your own function as well as the include statements like below: #ifdef LINUX #include <unistd.h> #endif #ifdef WINDOWS #include <windows.h> #endif void mySleep(int sleepMs) { #ifdef LINUX usleep(sleepMs * 1000); // usleep takes sleep time in us (1 millionth of a second) #endif #ifdef

How do I sleep for a millisecond in Perl?

喜夏-厌秋 提交于 2019-11-28 18:30:57
How do I sleep for shorter than a second in Perl? Chris Lutz From the Perldoc page on sleep : For delays of finer granularity than one second, the Time::HiRes module (from CPAN, and starting from Perl 5.8 part of the standard distribution) provides usleep(). Actually, it provides usleep() (which sleeps in microseconds) and nanosleep() (which sleeps in nanoseconds). You may want usleep() , which should let you deal with easier numbers. 1 millisecond sleep (using each): use strict; use warnings; use Time::HiRes qw(usleep nanosleep); # 1 millisecond == 1000 microseconds usleep(1000); # 1

What is a practical use for PHP's sleep()?

雨燕双飞 提交于 2019-11-28 17:20:56
问题 I just had a look at the docs on sleep(). Where would you use this function? Is it there to give the CPU a break in an expensive function? Any common pitfalls? 回答1: One place where it finds use is to create a delay . Lets say you've built a crawler that uses curl / file_get_contents to get remote pages. Now you don't want to bombard the remote server with too many requests in short time. So you introduce a delay between consecutive requests. sleep takes the argument in seconds, its friend

What's the equivalent of Java's Thread.sleep() in Objective-C/Cocoa?

不羁岁月 提交于 2019-11-28 17:15:50
问题 In Java you can suspend the current thread's execution for an amount of time using Thread.sleep(). Is there something like this in Objective C? 回答1: Yes, there's +[NSThread sleepForTimeInterval:] (Just so you know for future questions, Objective-C is the language itself; the library of objects (one of them at least) is Cocoa.) 回答2: Sleeping for one second in Java: Thread.sleep(1000); Sleeping for one second in Objective C: [NSThread sleepForTimeInterval:1.0f]; 回答3: Why are you sleeping? When

Thread.sleep vs. TimeUnit.SECONDS.sleep

允我心安 提交于 2019-11-28 16:09:23
If I'm going to have a call to have a Java Thread go to sleep, is there a reason to prefer one of these forms over the other? Thread.sleep(x) or TimeUnit.SECONDS.sleep(y) assylias TimeUnit.SECONDS.sleep(x) will call Thread.sleep . The only difference is readability and using TimeUnit is probably easier to understand for non obvious durations (for example: Thread.sleep(180000) vs. TimeUnit.MINUTES.sleep(3) ). For reference, see below the code of sleep() in TimeUnit : public void sleep(long timeout) throws InterruptedException { if (timeout > 0) { long ms = toMillis(timeout); int ns =

Python & Selenium: Difference between driver.implicitly_wait() and time.sleep()

空扰寡人 提交于 2019-11-28 14:35:50
Yes, I know both are used to wait for some specified time. Selenium: driver.implicitly_wait(10) Python: import time time.sleep(10) Is there any difference between these two? time.sleep(secs) time.sleep(secs) suspends the execution of the current thread for the given number of seconds. The argument may be a floating point number to indicate a more precise sleep time. The actual suspension time may be less than that requested because any caught signal will terminate the sleep() following execution of that signal’s catching routine. Also, the suspension time may be longer than requested by an

PHP echo before sleep function, not working

微笑、不失礼 提交于 2019-11-28 13:53:45
I want output echo in browser (every time) before sleep function execute. following code is not working set_time_limit(0); ob_implicit_flush(1); ob_start(); echo "Start<Br>"; ob_flush(); for($i=0;$i<10;$i++){ $randSlp=rand(1,3); echo "Sleeping for ".$randSlp." second. "; ob_flush(); sleep($randSlp); } ob_end_flush(); if uncomment str_repeat function than in browser First time : Start Sleeping for 1 second. Sleeping for 3 second. Second time : Sleeping for 2 second. Sleeping for 2 second. and continue... is possible echo one by one without str_repeat() function, why output doesn't display every