timer

Fast counting timer in JavaFX

℡╲_俬逩灬. 提交于 2019-12-14 02:36:03
问题 For effect, I want a label to display time like a stop watch would. The time starts at 0, and ends somewhere around 2 or 3 seconds. The service is stopped when desired. The issue I am having, is because I am trying to update the text 1000 times per second, the timer is lagging behind. Like I said, this is for effect and will be hidden as soon as the timer stops, but the time should be fairly accurate, not 3 seconds behind. Is there any way I can make this faster? I would like to have all 4

clock_gettime() returns bad results (Debian wheezy on VirtualBox)

人走茶凉 提交于 2019-12-14 02:33:21
问题 I am attempting to use clock_gettime() to monitor elapsed time. However it returns bad results. I tested it with the following: #include <time.h> #include <iostream> #include <math.h> using namespace std; int main() { // Time vars for calculation. int ns; // Initial struct. timespec tt; // Get starting time. clock_gettime(CLOCK_MONOTONIC,&tt); int ns_start = tt.tv_nsec; int s_start = tt.tv_sec; // Base for second wrap around. int ns_base = 1000e6 - ns_start; while(true) { cin.ignore(); // Get

Can ASIO timer `cancel()` call a spurious “success”?

偶尔善良 提交于 2019-12-14 02:29:31
问题 The ASIO documentation for basic_deadline_timer::cancel() has the following remarks section: If the timer has already expired when cancel() is called, then the handlers for asynchronous wait operations will: have already been invoked; or have been queued for invocation in the near future. These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation . The emphasis has been added by me. Normally when you call

Testing a Timer in Xcode with XCTest

馋奶兔 提交于 2019-12-14 01:30:04
问题 I have a function that does not need to be called any more than every 10 secs. Every time I invoke the function, I reset the timer to 10 secs. class MyClass { var timer:Timer? func resetTimer() { self.timer?.invalidate() self.timer = Timer.scheduledTimer(withTimeInterval: 10.0, repeats: false) { (timer) -> Void in self.performAction() } } func performAction() { // perform action, then self.resetTimer() } } I would like to test that calling performAction() manually resets the timer to 10 secs,

Anyway possible to make a countdown timer change color at an certain time with javascript? [closed]

主宰稳场 提交于 2019-12-13 23:37:12
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . Im trying to make a countdown timer that would change the color when reaches two different points, it supposed to go orange when reaches "00:59" and then change to red when reaches " 00:00 " How do I do that with javascript. <html> <head> <title>Countdown</title> <script type="text/javascript"> // set minutes

My timer in VB.NET is Losing one second

空扰寡人 提交于 2019-12-13 23:35:03
问题 I use a DateTimePicker to pick a dateTime value and see how much time I have until it is zero: Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick timeInSeconds = (DateTimePicker1.Value.Subtract(System.DateTime.Now)).ToString 'RichTextBox1.Text = RichTextBox1.Text + vbTab + timeInSeconds.ToString timeInSeconds = timeInSeconds.Substring(0, timeInSeconds.LastIndexOf(".")) End Sub The RichTextbox above shows that I loose a second at about each

How to fix a cross-thread exception in C#? [duplicate]

安稳与你 提交于 2019-12-13 22:25:24
问题 This question already has answers here : Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on (21 answers) Closed 5 years ago . I'm trying to use System.Timers.Timer on a UI control. The error: System.Timers.Timer "Cross-thread operation not valid: Control 'txtOutput' accessed from a thread other than the thread it was created on." My code is the following: System.Timers.Timer timeRandomEvent = new System.Timers.Timer(10 * 1000); // timer

Accurate three-minute time timer intervals

倖福魔咒の 提交于 2019-12-13 22:22:12
问题 In my previos question I asked about rounding time value to nearest third-minute. Well now I have some issues with my System.Threading.Timer that must work when is third-minute time is come. I Do following: private System.Timers.Timer WorkTimer; //... public void StartProccessing() { WorkTimer = new System.Timers.Timer(); WorkTimer.AutoReset = false; WorkTimer.Elapsed += new ElapsedEventHandler(WorkTimer_Elapsed); StartWorkTimer(); } //... private void StartWorkTimer() { WorkTimer.Interval =

How to deal with “runtime error 50290” when using SetTimer API?

一世执手 提交于 2019-12-13 19:50:37
问题 I've run into this error when trying to make a stopwatch timer in Excel. Here's a simple test code. Create an empty Excel workbook with a button. And assign a macro to it: Sub Button1_Click() TimerID = SetTimer(0&, 0&, 0.5 * 1000&, AddressOf TimerProc) End Sub Also, add this code to the module: Declare Function SetTimer Lib "user32" ( _ ByVal HWnd As Long, _ ByVal nIDEvent As Long, _ ByVal uElapse As Long, _ ByVal lpTimerFunc As Long) As Long Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As

Which thread will timer method run in?

被刻印的时光 ゝ 提交于 2019-12-13 18:41:20
问题 I looking to run a method periodically but would like to optimise my code by having it run in a separate thread. So far my code looks something like below: private System.Timers.Timer timerQuartSec = new System.Timers.Timer(250); private Thread quarterSecThread; timerQuartSec.Elapsed += new System.Timers.ElapsedEventHandler(someMethod); quarterSecThread = new Thread(new ThreadStart(timerQuartSec.Start)); My question is, would this code simply start the timer or would the code (on TimerElapsed