sleep

Sleep(suspend) and Resuming windows form starts program on worker thread instead of main thread

大兔子大兔子 提交于 2019-12-06 11:28:15
The windows form I am working on subscribes to Microsoft.Win32.SystemEvents.PowerModeChanged and on Suspend it runs the Close() method on the form. On Resume it runs the Run() function like it would on initial load. The problem is that when the computer is woken from sleep mode the PowerModeChanged event is triggered on a worker thread named ".Net SystemEvents" and when Run() is called it recreates the form on this worker thread instead of the main thread. This form is a project I inherited from another developer and I am new to windows form programming. I am wondering if there is a better way

join(long)与sleep(long)的区别

丶灬走出姿态 提交于 2019-12-06 10:43:57
1.join(long)方法的源码 首先看join()源码: public final void join() throws InterruptedException { join(0); } 从源码中可以看出,join()直接调用了join(long)方法,join(long)源码如下: public final synchronized void join(long millis) throws InterruptedException { long base = System.currentTimeMillis(); long now = 0; if (millis < 0) { throw new IllegalArgumentException("timeout value is negative"); } if (millis == 0) { while (isAlive()) { wait(0); } } else { while (isAlive()) { long delay = millis - now; if (delay <= 0) { break; } wait(delay); now = System.currentTimeMillis() - base; } } } 通过阅读源码可以看出,是通过不断轮询的方式去观察线程是否还是活动线程 join(0

XE4 Firemonkey on iOS prevent sleep mode

蓝咒 提交于 2019-12-06 08:19:38
问题 I am developing an app in Firemonkey XE4 for iOS and need to prevent the device from sleeping when there is no user input. I have found this command for xcode development: [application setIdleTimerDisabled:YES]; I presume there is an equivalent in FMX? Can anyone help please? Thanks Darryl 回答1: You can go straight to UIApplication, as so: uses iOSapi.UIKit; {$R *.fmx} procedure TForm6.Button1Click(Sender: TObject); var UIApp : UIApplication; begin UIApp := TUIApplication.Wrap(TUIApplication

nasm assembly linux timer or sleep

杀马特。学长 韩版系。学妹 提交于 2019-12-06 08:13:10
问题 I'm trying to find a way to make my code wait for two seconds before proceeding. I'm using nasm for Linux in protected mode, so I can only use int 80h. I found a syscall called " alarm " (27) and another called " pause " (29). However, when I try to use those, the program waits and finishes instead of continuing execution. I've also found another syscall , sigaction, which changes the behavior of a signal (so I think it can be used to make the program ignore the signal generated by alarm

How to use SleepEx with alertable true AND an overall minimum sleep time?

半世苍凉 提交于 2019-12-06 07:19:23
I have the following use case: My current thread needs to do operation1 , waits some amount of time to coordinate with others and afterwards needs to do operation2 . In between the waiting, APCs might need to be processed by that thread because of file system events, which add another operation1 to some queue to be processed later after operation2 is finished by the current thread. Something simple like the following: while (true) { processOperation1; SleepEx(..., true); processOperation2; } The important thing is that between operation1 and operation2 at least the specified amount of time to

Python freezes after computer sleep/hibernate

☆樱花仙子☆ 提交于 2019-12-06 06:03:32
I have a python script that is running in the background with pythonw. If I close my laptop, it goes into sleep mode. and when I open my laptop, my program has little functionality and freezes after a couple of seconds. Is there any way that my script can tell if my computer is going into sleep mode, so that it can lie dormant and restart when I re-open my laptop? You can catch WM_POWERBROADCAST window message with PBT_APMQUERYSUSPEND event inside it. To catch this message inside Python program, you can create new invisible window and make separate thread repeatedly calling GetMessage() . In

Object Serialization __sleep

匆匆过客 提交于 2019-12-06 05:48:34
问题 the php manual states: It can clean up the object and is supposed to return an array with the names of all variables of that object that should be serialized. i understand this as, if a had a class. Like this: <?php class Foo { public $bar = 'bar'; public $baz = 'baz'; public function __sleep() { return array('bar'); } } $obj = new Foo(); $serialized = serialize($obj); $unserialized = unserialize($serialized); var_dump($unserialized); ?> it would only serialize the object and the property

To sleep in C, should I use while with a clock, or a system call?

空扰寡人 提交于 2019-12-06 05:35:23
I was checking out clock() on cplusplus.com . Their example involves making the process wait for a second and then output a line, in a loop until 10 seconds have ellapsed. I need to do something similar in the homework assignment I'm working on. What I was wondering was this: if I just send my program into a loop, isn't that using system resources to just spin me around? In this case, wouldn't a system call be better? Thanks for your help! Yes, using a system call or library function like sleep() is much better. That clock() example is just meant to just show how to correctly call the function

OS X Cocoa timer not fired when application on background

坚强是说给别人听的谎言 提交于 2019-12-06 02:32:52
A third-party library provides a function I need to call every 100ms. Setting up a timer to do that works very well as long as my app is on foreground. When my app is on background timer works for a while but after a about a minute timer is called only after 10 second delay. The same happened when I created a separate thread with usleep-function. Is there any way I can keep timer running while my app is on background? Use beginActivityWithOptions:reason: to disable app nap for your application. You should try and re-architect to avoid these sorts of frequent timers, especially when your

Gradle - How to add some delay pause hang in Gradle

独自空忆成欢 提交于 2019-12-06 00:09:28
问题 Im looking for a way to insert a pause of few seconds between the calls of two gradle tasks. I can use firstTask.doLast { ..... } something like which can do Linux/Unix sleep 45 Any ideas? 回答1: First, I'd try to find a better solution than waiting for so long every time. Anyway, to delay the first task for 45 seconds, you can do: firstTask.doLast { sleep(45 * 1000) } A good way to familiarize yourself with Groovy's core APIs is to study the Groovy JDK (also known as GDK). It's also a handy