sleep

Proper Approach for Temporarily Suspending a Worker Thread

只愿长相守 提交于 2019-12-11 06:51:51
问题 I have a worker thread that may be active for short bursts of time and idle for rest of the time. I'm thinking to put the thread to sleep and then awake it when needed. Any additional recommendations for this I should be aware of? Thanks! this is in C#/.NET4 回答1: Just use an event to pause the worker thread: reset - paused, set - unpaused (working) state. Here is the draft version of code that demonstrates the approach. class Worker { private Thread _thread; // Un-paused by default. private

Non blocking wait while reading data from serial in VB

浪尽此生 提交于 2019-12-11 06:11:22
问题 I have a procedural GUI method that needs to retrieve data from serial several times. Each time it does so, it needs to wait for serial data function to finish (e.g., that function works for 15 seconds by averaging all the data received from the serial). What is some non blocking ways of waiting on this? At first I tried Threading.Thread.Sleep(15000) , however this locks up the program completely. I also tried very similar method (that still uses sleep but at smaller intervals). Blocking is

Lua microseconds sleep

元气小坏坏 提交于 2019-12-11 03:54:05
问题 Ok, I need to wait (for instance) for 10 us in my lua script. Is there any way to do it? For now I use this simple (non busy-waiting) function using socket : function my_utils.sleep(sec) socket.select(nil, nil, sec) end but it seems its "sleep minimum" is milliseconds. Example 1: for x=0,2*math.pi,0.008 do misc.printus() misc.sleep(0.001) end Output: 0.022654 0.023654 0.024654 0.025654 0.026654 0.027654 0.028654 0.029654 0.030654 0.031654 0.032654 ... Not bad! Example 2: for x=0,2*math.pi,0

Computer not obeying powercfg GUID command line instructions

醉酒当歌 提交于 2019-12-11 02:58:55
问题 I am trying to write a script to toggle the lid action between sleep/do nothing by using powercfg.exe and the relevant GUID. powercfg -SETACVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0 powercfg -SETDCVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0 To do nothing, and powercfg -SETACVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89

ASP.NET - Efficiently delay code execution for single request?

一曲冷凌霜 提交于 2019-12-11 02:58:03
问题 I would like to delay code execution for a single request (based in IP address) efficiently without affecting the overall server performance (so Thread.Sleep is not an option?). How can this be done? (this is to annoy specific people for a certain amount of time, while still providing correct functionality when the time is over..) 回答1: In my opinion, I wouldn't do such thing in your application layer, this is a Web server task rather than your own logic. Instead of that, what about this IIS

overlooping in C#

痞子三分冷 提交于 2019-12-11 02:29:34
问题 I am going to create a system service in C#. In the onstart section I would like to loop every 30 seconds and query a mysql database. If numrows are greater than 0 I will process some faxes using the faxcom library. My question is: Would looping every 30 seconds exhaust the program/computer? What would be the best function/method to use for the loop and sleep? Do you have any example code for the loop and sleep? 回答1: Using Thread.Sleep() would be a bad solution, because even while sleeping

Want to display number with 1sec delay

喜夏-厌秋 提交于 2019-12-11 02:25:27
问题 I want to display numbers in a TextView like this: Wait 5 sec // then a delay of 1 sec Wait 4 sec // display this in the same text view along with delay Wait 3 sec // display this in the same text view along with delay Wait 2 sec // display this in the same text view along with delay Wait 1 sec // display this in the same text view along with delay I want perform this action on a button click and it should work like a count down timer. 回答1: You can use this one new CountDownTimer(30000, 1000)

how to sleep accurately in a while loop in C (Linux)?

坚强是说给别人听的谎言 提交于 2019-12-11 01:49:42
问题 In a C code (Linux OS), I need to sleep accurately inside a while loop - say, 10000 microseconds for 1000 times. I have tried usleep, nanosleep, select, pselect, and some other methods with no success. Once in ~50 times it would sleep %100 longer (~20000 us). I need to perform an action after each delay. So, each delay has to be very accurate. Is there a way to do accurate sleeps for this case? Thanks.. EDIT: #include <stdio.h> #include <sys/time.h> int main(int argc, char *argv[]) { struct

Android AlarmManager RTC doesn't pause while device is sleeping

允我心安 提交于 2019-12-11 00:01:48
问题 I wrote a little widget for Android devices. The widget uses AlarmManager to set recurring updates. I'm using the RTC clock for the AlarmManager . According to the documentation, if the device is sleeping, the RTC clock won't wake up the device and the next update will be when the device is woken. I have a log file for the widget which shows when it was updated. Even when I don't touch the device , I still see updates in the log file. Why is that? shouldn't the device be sleeping and thus my