{"id":653,"date":"2016-11-24T10:18:16","date_gmt":"2016-11-24T10:18:16","guid":{"rendered":"https:\/\/ibex.tech\/windows-iot\/?p=176"},"modified":"2025-04-28T12:10:33","modified_gmt":"2025-04-28T11:10:33","slug":"dispatchertimer","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/uwp-programming-in-c\/timer-and-timing-uwp-programming-in-c\/dispatchertimer","title":{"rendered":"DispatcherTimer"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Using a DispatchedTimer To Call An Event Reguarly<br> <\/h4>\n\n\n\n<p><em>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&#8217;t make it any faster<\/em> <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\tprivate Windows.UI.Xaml.DispatcherTimer Timer1;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\t\/\/----- SETUP TIMER1 -----\n\tTimer1 = new Windows.UI.Xaml.DispatcherTimer();\n\tTimer1.Interval = TimeSpan.FromMilliseconds(500);\n\tTimer1.Tick += Timer1_Tick;\n\tTimer1.Start();\n\n\t\/\/Timer1_Tick(this, new object());\t\t\/\/Call function now (if you need to before page loads)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\t\/\/**********************************\n\t\/\/**********************************\n\t\/\/********** TIMER 1 TICK **********\n\t\/\/**********************************\n\t\/\/**********************************\n\tprivate void Timer1_Tick(object sender, object e)\n\t{\n\t\t\/\/Here every 500mS\n\t}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\tprivate void Page_Unloaded(object sender, RoutedEventArgs e)\n\t{\n\t\tTimer1.Stop();<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Using a DispatchedTimer to call async methods<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>private Windows.UI.Xaml.DispatcherTimer BackgroundAsyncTasksTimer;\n\n\t\/\/----- SETUP OUR BACKGROUND ASYNC TASKS TIMER -----\n\tBackgroundAsyncTasksTimer = new Windows.UI.Xaml.DispatcherTimer();\n\tBackgroundAsyncTasksTimer.Interval = TimeSpan.FromMilliseconds(100);\n\tBackgroundAsyncTasksTimer.Tick += BackgroundAsyncTasksTimer_Tick;\n\tBackgroundAsyncTasksTimer.Start();\n\n\n\t\/\/************************************************************\n\t\/\/************************************************************\n\t\/\/********** BACKGROUND ASYNC TASKS LOOPING THREAD ***********\n\t\/\/************************************************************\n\t\/\/************************************************************\n\tprivate async void BackgroundAsyncTasksTimer_Tick(object sender, object e)\n\t{\n\t\t\/\/Here every 100mS\n\n\t\tawait MyFunctionName();\n\t}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;t make it any faster Using a DispatchedTimer to call async methods<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[126],"tags":[],"class_list":["post-653","post","type-post","status-publish","format-standard","hentry","category-timer-and-timing-uwp-programming-in-c"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/653","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=653"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/653\/revisions"}],"predecessor-version":[{"id":1401,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/653\/revisions\/1401"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}