I'm trying to execute a Task with a timeout. But, when the task expires, it continue executing in a thread and I want to cancel it. This is part of the code:
var task = Task.Run(() => DoMethod());
if (task.Wait(TimeSpan.FromSeconds(timeout)))
result = task.Result;
return result;
I read about CancellationToken, but I don´t know how to implement it.