timer

High resolution timer with C++ and Linux?

情到浓时终转凉″ 提交于 2019-12-17 02:23:39
问题 Under Windows there are some handy functions like QueryPerformanceCounter from mmsystem.h to create a high resolution timer. Is there something similar for Linux? 回答1: It's been asked before here -- but basically, there is a boost ptime function you can use, or a POSIX clock_gettime() function which can serve basically the same purpose. 回答2: For Linux (and BSD) you want to use clock_gettime(). #include <sys/time.h> int main() { timespec ts; // clock_gettime(CLOCK_MONOTONIC, &ts); // Works on

java: run a function after a specific number of seconds

坚强是说给别人听的谎言 提交于 2019-12-16 22:21:26
问题 I have a specific function that I want to be executed after 5 seconds. How can i do that in Java? I found javax.swing.timer, but I can't really understand how to use it. It looks like I'm looking for something way simpler then this class provides. Please add a simple usage example. 回答1: new java.util.Timer().schedule( new java.util.TimerTask() { @Override public void run() { // your code here } }, 5000 ); EDIT: javadoc says: After the last live reference to a Timer object goes away and all

VBA Macro On Timer style to run code every set number of seconds, i.e. 120 seconds

社会主义新天地 提交于 2019-12-16 22:12:14
问题 I have a need to run a piece of code every 120 seconds. I am looking for an easy way to do this in VBA. I know that it would be possible to get the timer value from the Auto_Open event to prevent having to use a magic number, but I can't quite get how to fire off a timer to get something to run every 120 seconds. I don't really want to use an infinite loop with a sleep if I can avoid it. EDIT : Cross-post based on an answer provided is at: Excel VBA Application.OnTime. I think its a bad idea

System.Timers.Timer vs System.Threading.Timer

旧街凉风 提交于 2019-12-16 19:52:52
问题 I have been checking out some of the possible timers lately, and the Threading.Timer and Timers.Timer are the ones that look needful to me (since they support thread pooling). I am making a game, and I plan on using all types of events, with different intervals, etc. Which would be the best? 回答1: This article offers a fairly comprehensive explanation: "Comparing the Timer Classes in the .NET Framework Class Library" - also available as a .chm file The specific difference appears to be that

System.Timers.Timer vs System.Threading.Timer

天涯浪子 提交于 2019-12-16 19:51:16
问题 I have been checking out some of the possible timers lately, and the Threading.Timer and Timers.Timer are the ones that look needful to me (since they support thread pooling). I am making a game, and I plan on using all types of events, with different intervals, etc. Which would be the best? 回答1: This article offers a fairly comprehensive explanation: "Comparing the Timer Classes in the .NET Framework Class Library" - also available as a .chm file The specific difference appears to be that

file modification and creation

一个人想着一个人 提交于 2019-12-16 18:04:47
问题 How would you scan a dir for a text file and read the text file by date modified, print it to screen having the script scan the directory every 5 seconds for a newer file creadted and prints it. Is it possible that you can help me i'm stuck and i need this real bad and i've already got the scan dir for file and print but it does not print the files by date modidfied. import os,sys os.chdir(raw_input('dir_path: ') ) contents=os.listdir('.') #contents of the current directory files =[]

Stopping timer at defined amount of time in Swift

陌路散爱 提交于 2019-12-14 04:21:06
问题 I am trying to build a stopwatch which, for instance, will count to 3.0 seconds, stop, and then allow me to override the app's view with a new background/label. My issue is I cannot find a way for the timer to stop and pause on its own at 3 seconds - whenever I'd write the statement, it'd just continue counting and not do anything. Where would I put the statement in this code, and how would I write it? import UIKit class ViewController: UIViewController { var time = 0.0 var timer = Timer()

Make countdown start after button is clicked

只愿长相守 提交于 2019-12-14 04:17:57
问题 I'm creating a kid's game with a timer countdown that starts after the user clicks a button. The code I'm using initiates the countdown without a problem, but I'd like the countdown to start only after the button is clicked. Here is my code: window.onload = function(){ (function(){ var counter = 5; setInterval(function() { counter--; if (counter >= 0) { span = document.getElementById("count"); span.innerHTML = counter; } if (counter === 0) { alert('sorry, out of time'); clearInterval(counter)

how to update user location in both foreground and background every 10 seconds? [duplicate]

倾然丶 夕夏残阳落幕 提交于 2019-12-14 04:15:08
问题 This question already has an answer here : Update location in Background (1 answer) Closed last year . I'm making a location tracking app. In this app, I need to record user location every 10 seconds. Also, the recording is done in a background service so that the application does not need to be in foreground. To make this, I tried to use Timer but it's not working in background. I've tried so much but it didn't work. Could you help me please? I found this great tutorial: https://www

Make something happen after 5 minutes has passed, while other code still runs in C++

安稳与你 提交于 2019-12-14 04:07:09
问题 I am trying to make a timer, so after five minutes something happens. The catch is that while the timer is being checked constantly I need other code to be running. I have created a sample below, of how the actually code looks, the function with the timer is in class, so I did the same thing below. Here is the code: This code assumes all necessary headers are included Class.h: class MyClass { public: void TimerFunc(int MSeconds); }; void MyClass::TimerFunc(int MSeconds) { Sleep(MSeconds); /