sleep

Pause execution of a method without locking GUI. C#

≡放荡痞女 提交于 2019-11-30 13:27:57
问题 I'm working on a card game in C# for a project on my Intro to OOP paper and have got the game working now but am adding "flair" to the GUI. Currently cards are dealt and appear on the UI instantaneously. I want to have to program pause for a moment after dealing a card before it deals the next. When a game is started the following code runs to populate the PictureBoxes that represent them (will be a loop eventually): cardImage1.Image = playDeck.deal().show(); cardImage2.Image = playDeck.deal(

Sleeping in a Thread (C / POSIX Threads)

戏子无情 提交于 2019-11-30 12:38:09
I am developing a multithreaded application that makes use of POSIX Threads . I am using threads for doing a periodical job and for that purpose I am using usleep(3) to suspend thread execution. My question is how can I cancel usleep() timer from the main thread, I tried pthread_kill(thread, SIGALRM) but it has a global effect which results in termination of the main application (by default). Here is my pseudo code: void threaded_task(void *ptr) { initialize(); while(running) { do_the_work(); usleep(some_interval); } clean_up(); release_resources(); } And here is the pseudo function that is

Sleep function uses server resources?

♀尐吖头ヾ 提交于 2019-11-30 12:37:23
I've got two reasons to use a sleep function: first, to automatically send a confirmation email to a client 20 minutes after they contact us. I don't want to use cron jobs because I want it to be exactly 20 minutes (and I'm sick of my web server sending me emails telling me they initiated a cron job.....a new email every 20 minutes!) Second reason: I've heard of people sending out mass emails using the sleep function. Since my server will only allow 100 emails an hour, I want to use the sleep function to have the script sleep for an hour then continue where it picked up. My question is this:

How to use a timer to wait?

依然范特西╮ 提交于 2019-11-30 11:48:00
I am trying to delay events in my method by using a timer, however i do not necessarily understand how to use a timer to wait. I set up my timer to be 2 seconds, but when i run this code the last call runs without a 2 second delay. Timer timer = new Timer(); timer.Tick += new EventHandler(timer_Tick); // Everytime timer ticks, timer_Tick will be called timer.Interval = (1000) * (2); // Timer will tick evert second timer.Enabled = true; // Enable the timer void timer_Tick(object sender, EventArgs e) { timer.Stop(); } private void button1_Click(object sender, EventArgs e) { label1.Text = "first"

Undefined reference to “sleep” but I did include <unistd.h>

房东的猫 提交于 2019-11-30 11:45:14
Well, this must be a silly one. Here below is a can-not-be-simpler code in C. It can not compile saying "undefined reference to sleep". But I think I include all system header I need... #include <stdio.h> #include <unistd.h> int main() { printf("Test starts.\n"); sleep(1); printf("Test ends.\n"); return 1; } wazabit Try this at the top: #ifdef __unix__ # include <unistd.h> #elif defined _WIN32 # include <windows.h> #define sleep(x) Sleep(1000 * (x)) #endif This code will allow you to use two different functions under the same name, that do quite the same thing. And it compiles under different

Sleep and check until condition is true

删除回忆录丶 提交于 2019-11-30 11:15:19
Is there a library in Java that does the following? A thread should repeatedly sleep for x milliseconds until a condition becomes true or the max time is reached. This situation mostly occurs when a test waits for some condition to become true. The condition is influenced by another thread . [EDIT]Just to make it clearer, I want the test to wait for only X ms before it fails. It cannot wait forever for a condition to become true. I am adding a contrived example. class StateHolder{ boolean active = false; StateHolder(){ new Thread(new Runnable(){ public void run(){ active = true; } }, "State

How do I wake up a sleeping pthread?

一笑奈何 提交于 2019-11-30 09:57:44
I'm writing a program in C++. I've noticed that it's gaining a number of threads whose purpose is to do something at intervals, there are 3 or 4 of them. I decided to refactor by writing a scheduler service that the other places that use these threads could subscribe to, which should reduce the number of extra event threads I have running at any time to just one. I don't have any code that uses this yet; before I start writing it I'd like to know if it's possible, and get some feedback on my design. A brief description of what I'd like to accomplish is this: To add an event Caller provides an

Upper limit in Python time.sleep()?

非 Y 不嫁゛ 提交于 2019-11-30 09:38:47
问题 Is there an upper limit to how long you can specify a thread to sleep with time.sleep()? I have been having issues with sleeping my script for long periods (i.e., over 1k seconds). This issue has appeared on both Windows and Unix platforms. 回答1: I suppose the longer the time the more probable situation described in the docs: 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.

What event is fired when Mac is back from sleep?

别说谁变了你拦得住时间么 提交于 2019-11-30 09:12:20
I am developing an app in Xcode on Mac and would like to know the event which is fired when the mac gets back from sleep. AwakeFromNib doesn't seem to work. Thanks ! Laurent Crivello Just found it: - (void) receiveWakeNote: (NSNotification*) note { NSLog(@"receiveSleepNote: %@", [note name]); } - (void) fileNotifications { //These notifications are filed on NSWorkspace's notification center, not the default // notification center. You will not receive sleep/wake notifications if you file //with the default notification center. [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:

Sleep routine for HTA scripts

人盡茶涼 提交于 2019-11-30 09:07:00
问题 In several of my .HTA scripts that I created, I had the need for the VBScript WScript.Sleep command which simply waits for a number of milliseconds without utilizing the CPU. And when I browse the web, it appears that I am not the only one looking for this: https://www.google.nl/search?q=hta+sleep (I bet that if you read this, you probably need(ed) this as well) The best solution that I could find appears to be the one which uses the PING command. But especially for a situation were just need