I have timoeut between two tasks implemented as follows. If timeoutTask completes first, I would like to cancel ( or kill ) the workerTask, Is there anyway of doing this?
var timeoutTask = Task.Delay(1500);
var workerTask = Task.Run(() => { ThirdPartLibraryAPI.Run() });
var taskThatCompletedFirst = await Task.WhenAny(timeoutTask, workerTask);
//stuff to do on timeout can be done here
if (taskThatCompletedFirst == timeoutTask)
{
// At this point workerTask is still running.
// how can i cancel or kill this task
}