I'm creating a Windows service and so have the Program class inheriting from the ServiceBase class and overriding OnStart and OnStop. Inside these methods I have made use of TPL instead of using Threads like I would have done in the past. This what the methods look like:private CancellationTokenSource _cancellationTokenSource;protected override void OnStart(string[] args){    base.OnStart(args);    _cancellationTokenSource = new CancellationTokenSource();    CancellationToken cancellationToken = _cancellationTokenSource.Token;    Task task = Task.Run(async() =>    {        while (true)        {            if (!DoWork())            {                _cancellationTokenSource.Cancel();            }            else            {                await Task.Delay(1000);            }            if (cancellationToken.IsCancellationRequested)            {                break;            }        }    }, cancellationToken);}protected override void OnStop(){    _cancellationTokenSource.Cancel();    base.OnStop();}I was wondering if someone could just review the code to make sure it all looked fine.
Services and TPL
c#
while (true){    if (!DoWork())    {        _cancellationTokenSource.Cancel();    }    else    {        await Task.Delay(1000);    }    if (cancellationToken.IsCancellationRequested)    {        break;    }}Actually this could be a one-liner:while(!cancellationToken.IsCancellationRequested && DoWork()) await Task.Delay(1000);but why isn't DoWork awaitable and taking a cancellation token?while(!cancellationToken.IsCancellationRequested) await DoWork(cancellationToken);