Questions tagged [timer]
This tag is for questions about using timers in code to make things happen in a certain order or for gathering amount of time elapsed.
312 questions
3
votes
1
answer
189
views
Synchronize clock tick for timed action
The code shown below goes back to the tutorial How to Use a Timer in Tkinter.
I first simplified the tkinter import by restriction to Python 3.
Then I found a ...
0
votes
0
answers
32
views
Using react refs to control debouncing behaviour
I am learning about refs by using the React learning resources and encountered this challenge: https://react.dev/learn/referencing-values-with-refs#fix-debouncing
The provided solution uses a ref to ...
5
votes
2
answers
304
views
This is a simple stopwatch cli application with a few options
My goal of this when I started writing it was simply that it be able to record thousandths of a second in a very performant and accurate way. I'm not sure I have achieved the performance aspect of ...
3
votes
1
answer
252
views
Moving Timer from a View to a ViewModeller-class?
I have a Timer in my View right now, but I want to move it outside to my ViewModel-class. I have experimented a bit and came up with a working solution.
The code works and produces expected output, ...
6
votes
1
answer
1k
views
Threadsafe Non-Overlapping Timer
I was working on a project recently, where I needed to process some tasks periodically, but the execution of those tasks could not overlap with one another. ...
8
votes
1
answer
174
views
Simple reminders timer in C99 for POSIX
This is my first time trying out C. Simplicity was the main objective. Signals are not handled and memory is not freed (program is very small, and the OS should take care of that when program exits).
...
3
votes
1
answer
121
views
scoped timer class (3rd revision)
Again, here is the previous question. I have (re)revised my custom scoped timer using the valuable feedback I got from a helpful member of this community. However I feel the need to ask this question ...
3
votes
1
answer
2k
views
Script to stop a program after a certain amount of time
I created this script because the Spotify desktop app doesn't have a built in sleep timer, and I needed one. I made it as easy to use as possible, and it can close other programs because it asks for ...
5
votes
2
answers
269
views
Basic scoped timer struct (extensively redesigned)
Here is the original question. I have extensively revised and redesigned my custom scoped timer for my needs using the feedback I got from two helpful members of this community. However I was told to ...
5
votes
1
answer
322
views
Function to format time, from seconds to a particular expresion
From an integer X representing a time duration in seconds produce a simplified string representation.
For example, given X=100, you should output: "1m40s"
Use the following abbreviations w,d,...
0
votes
1
answer
136
views
Creating custom setTimout function using requestAnimationFrame loop
I created a function using requestAnimationFrame loop that works pretty much like the plain JS setTimeout function (except that ...
5
votes
3
answers
2k
views
Heartbeats per minute in vanilla HTML JS
Attached is a fun little snippet demonstrating a button to be clicked along with your heartbeat and see how many beats per minute you're at. This is a mwe of the concept, any feedback is appreciated.
...
5
votes
1
answer
780
views
Bash script simple countdown timer with dotted output
My goal is to have a timer function that operates from the bash linux command line. I am looking for review and feedback. Printing the expected number of characters (dots, dashes, or bars) is nice-...
4
votes
1
answer
3k
views
Timer thread implementation
I've implemented a timer thread whose job is to call functions at a certain interval. The functions may be called multiple times if their interval > 0 millisec otherwise only one time. Even if the ...
4
votes
2
answers
202
views
I wrote a simple time measurement/compare library in C++ [TimeIt]
C++ Timeit
A quick C++ library to measure/compare code execution time
Features
Easy include and just call timeit() or ...
2
votes
1
answer
606
views
Clear output line in terminal after use for countdown (different length strings)
The method to overwrite the same line is well known and I use it for countdown, but what about when the next output string has a different size and will be generated by a single print? That's the ...
5
votes
3
answers
529
views
Templatizing a Timer class
I'm making a timer class in C++. This is the overview:
...
2
votes
1
answer
228
views
Timer with input, sound and flashing
I know that this program is not very outstanding, but I'm learning Python and decided to publish this code in order to get some advice and parting words and overall evaluation of the program. This is ...
2
votes
1
answer
238
views
Program to check if a window is opened or not during some time interval
I'm trying to write a program that will check if a window is opened or not, during a given time. I was able to do that, but now I'm trying to make my code look cleaner. I don't like how I implement ...
6
votes
3
answers
1k
views
Python analog clock with turtle - runs slow
I made a python analog clock program with turtle. The problem is, it takes about 1.4 seconds to loop, so it only moves the second hand every 1.4 seconds. Its probably cuz my computer is slow...
...
8
votes
0
answers
850
views
A VBA program to quantify the performance of code execution timers
Motivation
I am interested in optimising the execution time of code with short (fast) execution times on the order of microseconds (µs), but that will be used with high frequency (e.g. like ...
2
votes
1
answer
387
views
Leaky Bucket Algorithm with no Queue
Basic implementation of a leaky bucket, the idea is you call it by saying I will allow e.g. 5 login attempts per 60 seconds.
...
6
votes
3
answers
2k
views
Safe Windows API Timers for Excel
Update Feb 2023
This solution is no longer maintained here or on GitHub, mainly because I do not need a timer solution anymore. As seen below, the only purpose of this approach was to get a reliable, ...
3
votes
2
answers
2k
views
Retry a callback function n times until success
I want to make a function to retry calling callback n times until it return TRUE;
Here's my current code:
...
4
votes
9
answers
814
views
Simple stop watch class
I've made a little library where I add some functionalities from time to time that I miss in the Java standard library.
I am sad that the Java library for example has no stop watch class that allows ...
3
votes
1
answer
853
views
Simple stopwatch in C
A very simple stopwatch. Intended to be used for simple benchmarking when you want to do a task several times, but exclude some setup code from the benchmarking.
Some things I have already considered:
...
3
votes
1
answer
1k
views
Timer for event throttling
I have the following problem. I want to write a class that handles events and passes it through but reduce its number if there recently was an event. Basically it is debounce. However there is a ...
7
votes
2
answers
5k
views
Time duration conversion with units
I recently was asked to upgrade some C++11 code to add a feature by which the user can set a time duration from the command line of the program. The requirement was to have a default time of 1500 ms ...
6
votes
3
answers
1k
views
A priority based timer using priority queue
I am trying to implement a priority-based timer where certain events are fired out based on their expiry and the priority.
So if there are 3 timers with the following expiry time and priorities
Timers
...
2
votes
1
answer
975
views
watchdog for c++11
I created a watchdog/notifier in C++ and wanted to make it better so it could be used by multiple people. The idea is that there is a timer class and event. client create events and pass a lambda ...
7
votes
1
answer
978
views
Digital clock with Python Tkinter
While learning about python tkinter, I decided to make a digital clock:
...
3
votes
0
answers
295
views
C# class library for managing recurring background operations
I have written a class library for creating timer-based bacground operations in .NET projects. The idea is to be able to create and manage (start/stop/resume/cancel) recurring background operations ...
3
votes
0
answers
89
views
Python script that getting list of all files with specific ext starting from the current folder. Using timer for reporting about the process
I am using a function that returns a list of all files (full path for each of them) with the given extension in the given folder and all subfolders.
As the process is quite long and user can get ...
2
votes
3
answers
7k
views
A Countdown Timer with reset functionality in pure Javascript
This works for me, but is this the right way to create this timer?
I might be naive about this but I think this is close to perfect in pure JS.
What would be the drawbacks of using this Timer compared ...
3
votes
1
answer
749
views
Windows high resolution timing class
I'm attempting to implement a high resolution class used to time the execution time of functions in Windows. After using this documentation, I have come up with the following:
...
2
votes
1
answer
86
views
Detect discontinuities in Windows clock in Java
Please review the code below, which detects discontinuities in Windows system clock in long-running programs.
...
4
votes
2
answers
918
views
Timer with interval function
I've been tasked with writing a function that executes a passed function every interval, passed to the function by the user. Below is the code, and how to call it:
...
1
vote
1
answer
133
views
Allow adding errors and warnings and remove both after a while with seperate timers
I use this in my Blazor application, letting other services send errors or warnings to this AlertService. The service triggers an update of a component which simply displays the messages, errors in ...
4
votes
0
answers
185
views
Just a digital clock in Swing
I've written a little clock implementation in Java Swing. It now seems to work flawlessly after having terrible Swing specific timing problems. Please indicate if this is the way to draw the clock and ...
3
votes
0
answers
64
views
n executions of a periodic goroutine
I'm new to Go and have a use-case for periodically executing an async work-function. I want the interval between work-function executions to be constant (not the time between one finishing and the ...
8
votes
1
answer
246
views
JS stopwatch using the observer pattern
I'm learning OOP and also trying to learn and implement some design patterns.
This question is a follow-up of Stopwatch interface OOP (Vanilla JS)
The app is available in https://nacho-p5.github.io/
...
8
votes
3
answers
439
views
Stopwatch interface OOP (Vanilla JS)
I'm learning OOP and the first exercise of the course was to made a Stopwatch class. I did it really fast and decided to make an interface for this little app.
I created the interface. Basically I ...
2
votes
0
answers
66
views
Refresh the List box with new rooms from the server every 3 seconds [closed]
So i have a server which I send a Request to and it sends me back a list of rooms,Now i made a window for joining rooms and I'm trying to refresh it every 3 seconds but when i use the Timer thread to ...
1
vote
2
answers
856
views
sleepless timer that does not lose time and handles spurious wakes
I have written a timer class.
Here it is in all its "glory" with some functions around it to test it:
https://rextester.com/LQSXUA43758
Below is the class on its own, note it also relies on ...
0
votes
1
answer
973
views
Run a timer while waiting for user input [closed]
I am making a C# console maths test where the user answers maths questions.
I am trying to add a timer to the test, I have managed to make a timer but when I run my code it becomes a mess!
Here is ...
2
votes
2
answers
107
views
Simple Timer Program
I have built a timer program in JavaScript. It decrements one counter every second, and if that counter is at zero, it decrements another counter, and sets the first counter to 59. If the second ...
2
votes
1
answer
2k
views
Timer in Java with GUI
I have created a timer with GUI in Java.
Here's the code:
...
3
votes
1
answer
3k
views
Timer for scheduling tasks in C++11
I have made a simple Timer class used for scheduling tasks. While defining the interface, I have followed the interface of a ...
3
votes
1
answer
458
views
ValueAnimator for IOS - Did I butcher it up?
I am trying to make an IOS tool similar to Android's ValueAnimator... more or less
This is useful for situations where you simply want a value to "animate" over time, but rather than necessarily ...
6
votes
2
answers
363
views
Productivity/Timer app that uses twilio to send SMS-reminders
I wrote a timer app in python using both twilio and the timer module; sends an sms to my phone after a certain amount of time has passed. While it works without a doubt, I wanted to gather some ideas/...