title: Executing a function periodically after the function completes its task
body: <p>I am building a windows store app using C# and xaml. I need to refresh the data after certain interval of time (bring the new data from the server). I used ThreadPoolTimer to execute my refresh function periodically as follows:</p>
  
  <pre><code>   TimeSpan period = TimeSpan.FromMinutes(15); 
     ThreadPoolTimer PeriodicTimer =  ThreadPoolTimer.CreatePeriodicTimer(async(source)=&gt; {  
     n++; 
     Debug.WriteLine("hello" + n);
     await dp.RefreshAsync(); //Function to refresh the data
     await Dispatcher.RunAsync(CoreDispatcherPriority.High,
                  () =&gt;
                  {
                      bv.Text = "timer thread" + n;
  
                  });
  
          }, period);
  </code></pre>
  
  <p>This is working properly. The only problem is that what if refresh function doesnot complete before its next instance is submitted to the thread pool. Is there some way to specify the gap between its execution.</p>
  
  <p>Step 1 : Refresh function executes (takes any amount of time)</p>
  
  <p>Step 2 : Refresh function completes its execution</p>
  
  <p>Step 3 : Gap for 15mins then go to Step 1</p>
  
  <p>Refresh function executes. 15mins after its execution ends, it executes again.</p>