title: Best way to do a task looping in Windows Service
body: <p>I have a method that send some SMS to our customers that look like below:</p>
  
  <pre><code>public void ProccessSmsQueue()
  {
     SmsDbContext context = new SmsDbContext();
     ISmsProvider provider = new ZenviaProvider();
     SmsManager manager = new SmsManager(context, provider);
  
     try
     {
        manager.ProcessQueue();
     }
     catch (Exception ex)
     {
        EventLog.WriteEntry(ex.Message, EventLogEntryType.Error);
     }
     finally
     {
        context.Dispose();
     }
  }
  
  protected override void OnStart(string[] args)
  {
     Task.Factory.StartNew(DoWork).ContinueWith( ??? )
  }
  </code></pre>
  
  <h2>So, I have some issues:</h2>
  
  <ol>
  <li><p>I don´t know how long it takes for the method run;</p></li>
  <li><p>The method can throw exceptions, that I want to write on EventLog</p></li>
  <li><p>I want to run this method in loop, every 10 min, <strong>but only after last execution finish.</strong></p></li>
  </ol>
  
  <p>How I can achieve this? I thought about using <code>ContinueWith()</code>, but I still have questions on how to build the entire logic.</p>