I managed to create a watch with the following code:
ThreadPoolTimer Timer1 = ThreadPoolTimer.CreatePeriodicTimer(Timer1_ElapsedHandler, TimeSpan.FromSeconds(1)); clockTick = false; UpdateLoop();
For this you need an event handler, in my watch it is established that the timer is marked:
public void Timer1_ElapsedHandler(ThreadPoolTimer timer) { clockTick = true; }
Then, to update the GUI (or whatever you need), there is an update loop:
public async void UpdateLoop() { do { await Task.Delay(100); } while (!clockTick); ClockTextBlock.Text = DateTime.Now.ToString(); clockTick = false; UpdateLoop(); }
Wrapping this in the class and clearing it up a bit can probably give you the basis for a good timer without a user interface.
source share