title: How to call a method every x seconds for x time in Xamarin Forms?
body: <p>I am making an application in Xamarin Forms in which I need to call a method every x time for x time (e.g. every 5 seconds for 2 minutes). How can it be done?</p>
  <p>I have only found information on how to call a method every x time, but this is not enough for what I am looking for.</p>
  <p>This is what I have tried. This calls <code>MyMethod</code> after 15 seconds have elapsed:</p>
  <pre><code>await Task.Delay(new TimeSpan(0, 0, 15)).ContinueWith(async o =&gt;
  {
      MyMethod();
  });
  </code></pre>
  <p>And this calls <code>MyMethod</code> every 5 seconds:</p>
  <pre><code>var startTimeSpan = TimeSpan.Zero;
  var periodTimeSpan = TimeSpan.FromSeconds(5);
  
  var timer = new System.Threading.Timer((e) =&gt;
  {
      MyMethod();
  }, null, startTimeSpan, periodTimeSpan);
  </code></pre>
  <p>What I need is to call <code>MyMethod</code> every x seconds for x amount of time.</p>