I need to cancel task that using a long-running method from dll (MethodFromDll() in this example) Where I can call cancellationToken.ThrowIfCancellationRequested() method to cancel this Task?
tokenSource = new CancellationTokenSource();
CancellationToken cancellationToken = tokenSource.Token;
t = Task.Factory.StartNew(() => {
try {
...some code
// I need to cancel this task manually if method not answer
// or there is no wish to wait
MethodFromDll();
...some code
} catch {
...some code
}
}, cancellationToken);