Using a DispatchedTimer To Call An Event Reguarly
Note: A 45mS tick seems to be about the fastest this can be used for in our tests on a RPi 3, lower values don’t make it any faster
private Windows.UI.Xaml.DispatcherTimer Timer1;
//----- SETUP TIMER1 -----
Timer1 = new Windows.UI.Xaml.DispatcherTimer();
Timer1.Interval = TimeSpan.FromMilliseconds(500);
Timer1.Tick += Timer1_Tick;
Timer1.Start();
//**********************************
//**********************************
//********** TIMER 1 TICK **********
//**********************************
//**********************************
private void Timer1_Tick(object sender, object e)
{
//Here every 500mS
}
private void Page_Unloaded(object sender, RoutedEventArgs e)
{
Timer1.Stop();
Using a DispatchedTimer to call async methods
private Windows.UI.Xaml.DispatcherTimer BackgroundAsyncTasksTimer;
//----- SETUP OUR BACKGROUND ASYNC TASKS TIMER -----
BackgroundAsyncTasksTimer = new Windows.UI.Xaml.DispatcherTimer();
BackgroundAsyncTasksTimer.Interval = TimeSpan.FromMilliseconds(100);
BackgroundAsyncTasksTimer.Tick += BackgroundAsyncTasksTimer_Tick;
BackgroundAsyncTasksTimer.Start();
//************************************************************
//************************************************************
//********** BACKGROUND ASYNC TASKS LOOPING THREAD ***********
//************************************************************
//************************************************************
private async void BackgroundAsyncTasksTimer_Tick(object sender, object e)
{
//Here every 100mS
await MyFunctionName();
}
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.