title: Basic design pattern for using TPL inside windows service for C#
body: <p>I am trying to build up windows service which need some kind of parallelism for pooling files from different ftp sources. For starting multiple ftp downloads I am looking in TPL library to easily do foreach loops and making parallelism totally easy. But when I search how to start or stop my service(s), best shot I fund is to make new threads inside <code>OnStart()</code> method, as it is described here <a href="https://stackoverflow.com/a/4865893/69433">https://stackoverflow.com/a/4865893/69433</a></p>
  
  <p>Reading about TPL there is always note that TPL is more advanced than manual threading and manual stop threading.</p>
  
  <p>I did not find any sample post which describes how to make TPL loop inside WindowsService ?</p>
  
  <p>My code:</p>
  
  <pre><code>protected override void OnStart(string[] args)
  {
       _thread = new Thread(WorkerThreadFunc);
       _thread.Name = "My Worker Thread";
       _thread.IsBackground = true;
       _thread.Start();
  }
  </code></pre>
  
  <p>And inside <code>WorkerThreadFunc</code> to do sme kind of TPL</p>
  
  <pre><code>private void WorkerThreadFunc()
  {
  foreach (string path in paths)
  {
      string pathCopy = path;
      var task = Task.Factory.StartNew(() =&gt;
          {
              Boolean taskResult = ProcessPicture(pathCopy);
              return taskResult;
          });
      task.ContinueWith(t =&gt; result &amp;= t.Result);
      tasks.Add(task);
  }
  
  }
  </code></pre>
  
  <p>Or I should start my WorkerThreadFunc also as TASK ?</p>