title: Do I need to terminate Task in windows service in OnStop method?
body: <p>So I have a Windows Service
  And I started task in OnStart</p>
  
  <pre><code>   partial class AppServices : ServiceBase
      {
          private static readonly ILog Log = LogManager.GetCurrentClassLogger();
          private Task _task;
  
          public AppServices()
          {
              InitializeComponent();
          }
  
          protected override void OnStart(string[] args)
          {
              Log.Info("Service started");
  
              _task = Task.Factory.StartNew(StartWork, TaskCreationOptions.LongRunning);
          }
  
          protected override void OnStop()
          {
              Log.Info("Service stopped");
          }
  
          private void StartWork()
          {
             while(true)
             {
                 // grab some data from db or services
             }
         }
  </code></pre>
  
  <p>Do I need to add CancellationToken and stop Task in OnStop or it is unnecessary? Because when service will stop - Task stops as well. Does it safe or not?</p>