using System.Threading; using System.Threading.Tasks; public async Task StartTask(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { // Do some work } // Task was cancelled }In this example, the StartTask method takes a CancellationToken as a parameter, which is used to check if the task has been cancelled. The method enters a loop to do some work, and keeps going until the CancellationToken.RequestCanceled property is true. The package library for this example is the System.Threading.Tasks package.