I am building a windows store application using c # and xaml. I need to update the data after a certain period of time (bring new data from the server). I used ThreadPoolTimer to execute my update function periodically as follows:
TimeSpan period = TimeSpan.FromMinutes(15); ThreadPoolTimer PeriodicTimer = ThreadPoolTimer.CreatePeriodicTimer(async(source)=> { n++; Debug.WriteLine("hello" + n); await dp.RefreshAsync(); //Function to refresh the data await Dispatcher.RunAsync(CoreDispatcherPriority.High, () => { bv.Text = "timer thread" + n; }); }, period);
This is working correctly. The only problem is that if the update function does not end before its next instance is sent to the thread pool. Is there a way to indicate the gap between its execution.
Step 1: The update function is running (takes some time)
Step 2: update function completes execution
Step 3: 15 minutes clearance, then go to Step 1
The update function is running. 15 minutes after completion of execution, it is executed again.
source share