timer

How to stop a running TimerTask

故事扮演 提交于 2020-01-11 04:28:11
问题 I am trying to make a simple timer that plays a beep after the specified number of seconds. I managed to get it to work, but the TimerTask continues to run after the beep. Now do I stop execution? Here is my code: import java.util.Scanner; import java.util.Timer; import java.util.TimerTask; import java.awt.Toolkit; class Alarm { public static void main(String[] args) { long delay; Scanner scan = new Scanner(System.in); System.out.print("Enter a delay in seconds: "); delay = scan.nextInt()

How to stop a running TimerTask

匆匆过客 提交于 2020-01-11 04:28:06
问题 I am trying to make a simple timer that plays a beep after the specified number of seconds. I managed to get it to work, but the TimerTask continues to run after the beep. Now do I stop execution? Here is my code: import java.util.Scanner; import java.util.Timer; import java.util.TimerTask; import java.awt.Toolkit; class Alarm { public static void main(String[] args) { long delay; Scanner scan = new Scanner(System.in); System.out.print("Enter a delay in seconds: "); delay = scan.nextInt()

Count for 45 seconds, pause for 20 then repeat with different title

旧城冷巷雨未停 提交于 2020-01-11 03:48:11
问题 In trying to limit battery usage I need to not have busy loops, so I am not certain how to solve this problem. If I have a program that will allow someone to sing for 45 seconds, then they pause for 20 seconds to get a drink, then repeat, for some number of songs. My timer is at Problem getting timer to work after cancelling one iteration and starting another, but in order for this to work, when someone clicks on a button it starts the first countdown, but the times were queued up, and the

how to make DispatcherTimer events smoother in WPF?

谁说胖子不能爱 提交于 2020-01-11 02:04:11
问题 In my WPF application, the user presses a button to start a 3D model rotating smoothly, and lets up on the button to stop the rotation. To do this, I create a DispatcherTimer: DispatcherTimer timer = new DispatcherTimer(); timer.Tick += new EventHandler( timer_Tick ); timer.Interval = new TimeSpan( 0, 0, 0, 0, 30 ); And when the button is pressed I call timer.Start() and when the button is let up I call timer.Stop() . The timer_Tick function changes the rotation of the model: void timer_Tick(

Monotonically increasing time in JavaScript?

两盒软妹~` 提交于 2020-01-10 07:31:29
问题 What’s the best way to get monotonically increasing time in JavaScript? I’m hoping for something like Java’s System.nanoTime() . Date() obviously won’t work, as it’s affected by system time changes. In other words, what I would like is for a <= b, always : a = myIncreasingTime.getMilliseconds(); ... // some time later, maybe seconds, maybe days b = myIncreasingTime.getMilliseconds(); At best, even when using the UTC functions in Date() , it will return what it believes is the correct time,

Flutter Countdown Timer

主宰稳场 提交于 2020-01-09 16:51:07
问题 How can I do to put the value passed in the construction, to make a timer that rounds to the first decimal and shows at the child text of my RaisedButton? I've tried but without luck. I manage to make work the callback function with a simple Timer but no periodic and with no update of value in real time in the text... import 'package:flutter/material.dart'; import 'dart:ui'; import 'dart:async'; class TimerButton extends StatefulWidget { final Duration timerTastoPremuto; TimerButton(this

C# Why are timer frequencies extremely off?

跟風遠走 提交于 2020-01-09 13:08:50
问题 Both System.Timers.Timer and System.Threading.Timer fire at intervals that are considerable different from the requested ones. For example: new System.Timers.Timer(1000d / 20); yields a timer that fires 16 times per second, not 20. To be sure that there are no side-effects from too long event handlers, I wrote this little test program: int[] frequencies = { 5, 10, 15, 20, 30, 50, 75, 100, 200, 500 }; // Test System.Timers.Timer foreach (int frequency in frequencies) { int count = 0; //

C# Why are timer frequencies extremely off?

大兔子大兔子 提交于 2020-01-09 13:07:47
问题 Both System.Timers.Timer and System.Threading.Timer fire at intervals that are considerable different from the requested ones. For example: new System.Timers.Timer(1000d / 20); yields a timer that fires 16 times per second, not 20. To be sure that there are no side-effects from too long event handlers, I wrote this little test program: int[] frequencies = { 5, 10, 15, 20, 30, 50, 75, 100, 200, 500 }; // Test System.Timers.Timer foreach (int frequency in frequencies) { int count = 0; //

C# Why are timer frequencies extremely off?

白昼怎懂夜的黑 提交于 2020-01-09 13:07:42
问题 Both System.Timers.Timer and System.Threading.Timer fire at intervals that are considerable different from the requested ones. For example: new System.Timers.Timer(1000d / 20); yields a timer that fires 16 times per second, not 20. To be sure that there are no side-effects from too long event handlers, I wrote this little test program: int[] frequencies = { 5, 10, 15, 20, 30, 50, 75, 100, 200, 500 }; // Test System.Timers.Timer foreach (int frequency in frequencies) { int count = 0; //

Update JPanel and attributes in a gui, with a user-specified timer?

99封情书 提交于 2020-01-09 11:40:10
问题 So I have this class. We'll call it ProcessBox. I have another class called Process that has a ProcessBox as a member variable. Then, in my main method I have an ArrayList of Process objects (each having their own ProcessBox). How would I go about making it so that my ProcessBox would update every x ms (where x is user specified. I already have the listener for inputting x done). Below is my ProcessBox class. This is what I wish to redraw every x ms (except a whole list of them). import java