我需要取消使用dll中长时间运行的方法的任务(本例中为MethodFromDll()) 我可以在哪里调用cancellationToken.ThrowIfCancellationRequested()方法来取消这个任务?
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);