timer

how to implement timer's callback function in C under Linux

南笙酒味 提交于 2019-12-21 20:07:13
问题 I have searched the possible solution on many forums for several days but have no luck; ( I post my question here and your reply is greatly appreciated. IDEA: Use a script to control lights (in C under Linux) APPLICATION SCENARIO I have three lights: red, blue and green. The script has the schedules to control them. For example, From now in 10 seconds, turn on the red light for 2 seconds; From now in 15 seconds, turn on the blue light for 10 seconds; From now in 21 seconds, turn on the red

Java Event Listener on Clock Minute change

别等时光非礼了梦想. 提交于 2019-12-21 19:59:23
问题 I am looking for the best way in Java to monitor the computer clock (the minutes) and to fire off a method/thread every time it changes. So if the time is 13:20 and it changes to 13.21 then do something. So any time there is a minute change some code gets fired. What is the best way to listen to the minute section of the clock for changes ? Thanks, Richard 回答1: Date d = new Date(System.currentTimeMillis()); Then you can get the minutes by d.getMinutes() . Have a check running in a thread

Timer Task stops running after indefinite time in android

点点圈 提交于 2019-12-21 17:51:23
问题 I am a newbie in android. I am developing an app in which a particular piece of code executes after every 5 seconds in background.To achieve this I am using a service with timer with a timer task in it. For sometime its working fine but after some indefinite my service is running but timer task stops automatically in android. Here is my code please help. Thanks in advance. public void onStart(Intent intent, int startid) { //this is the code for my onStart in service class int delay = 1000; //

Wait for signal, then continue execution

感情迁移 提交于 2019-12-21 17:37:51
问题 I am trying to make a program that suspends its execution until a signal arrives . Then, after the signal arrives I just want my code to continue its execution from where it was . I don't want it to execute a function handler or whatsoever. Is there a simple way of doing this? I have been struggling for a week or so, reading here and there, and didn't manage to get a fully operative code. In particular, I want the main program to create a thread that waits for some particular event to happen

How to Implement a timer in Metro Style App

拈花ヽ惹草 提交于 2019-12-21 17:37:07
问题 I am developing a game in which I have to implement timer for showing the time that has elapsed. How can I do that? 回答1: The async/await way: private bool isTimerRunning; private async void StartTimer() { this.isTimerRunning = true; while (this.isTimerRunning) { OnOneSecondPassed(); await Task.Delay(1000); } } private void StopTimer() { this.isTimerRunning = false; } protected virtual void OnOneSecondPassed() { } 回答2: Did you try to use DispatcherTimer in namespace Windows.UI.Xaml ? If this

Timer that supports overlapped I/O (for IOCP)?

我的梦境 提交于 2019-12-21 16:17:29
问题 I need to add timers support in an application based on I/O Completion Ports (IOCP). I would like to avoid the use of a specific thread to manage timers. On Linux, you can create a timer that delivers expiration notifications via a file descriptor (see timerfd.h man), so it's great to use it for example with epoll if your application is based on epoll. On Windows, you can use "waitable timers" with an asynchronous procedure call (ACP) (see http://msdn.microsoft.com/en-us/library/ms686898(v=VS

using ScheduledExecutorService to start and stop timer

六月ゝ 毕业季﹏ 提交于 2019-12-21 14:59:28
问题 From my readings, it seems that ScheduledExecutorService is the right way to start and stop timers in Java. I need to port some code that starts and stops a timer. This is not a periodic timer. This code, stops the timer before starting it. So, effectively every start is really a restart(). I am looking for the right way to do this using the ScheduledExecutorService. Here is what I came up with. Looking for comments and insight on things I am missing: ScheduledExecutorService _Timer =

java.lang.IllegalStateException: TimerTask is scheduled already: Rationally using of Timer and TimerTask in Android

二次信任 提交于 2019-12-21 12:57:23
问题 I write an application that connects to server and sends him ping commands, server answer with pong commands. I want to implement connection timeout mechanism. I think it will be following: Client send ping and start timer with timertask and delay When client receive pong , timertask is cancelled. Also, I want to optimize memory. So, not to recreate TimerTask every time I send ping command. I try code below: private final Timer mSystemLogoutTimer = new Timer(); private final TimerTask

To execute a function every x minutes: sched or threading.Timer?

限于喜欢 提交于 2019-12-21 10:16:00
问题 I need to program the execution of a give method every x minutes. I found two ways to do it: the first is using the sched module, and the second is using Threading.Timer . First method : import sched, time s = sched.scheduler(time.time, time.sleep) def do_something(sc): print "Doing stuff..." # do your stuff sc.enter(60, 1, do_something, (sc,)) s.enter(60, 1, do_something, (s,)) s.run() The second : import threading def do_something(sc): print "Doing stuff..." # do your stuff t = threading

Is it okay to attach async event handler to System.Timers.Timer?

假如想象 提交于 2019-12-21 09:09:21
问题 I have already read SO post here and article here I have a timer event that fires every once in a while and i want to do some asynchronous processing inside the handler, so something along the lines of: Timer timer = new Timer(); timer.Interval = 1000; timer.Elapsed += timer_Elapsed; // Please ignore this line. But some answers already given based on this line so I will leave it as it is. timer.Elapsed += async (sender, arguments) => await timer_Elapsed(sender, arguments); private async Task