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();
	}
UK Electronic Designer
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.