本文介绍了如何取消CSharpScript.RunAsync的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何停止RunAsync?
How can I stop RunAsync?
CancellatioTokenSource cts = new CancellationTokenSource();
//I thought that it's must work, but it don't
var script = CSharpScript.Create(code: someCode);
await script.RunAsync(cancelletionToken: cts.Token);
void button_click()
{
cts.Cancel()
}
我还能怎么做。以及为什么这些方法需要cancelToken参数?
How else can I do this. And for why such methods need cancellationToken parameter?
推荐答案
您必须在等待$之前执行此操作c $ c>调用,它将阻止执行直到获得结果为止,例如:
You must do it before the await
call, which blocks execution until yout get results, e.g.:
var task = script.RunAsync(cancelletionToken: cts.Token);
cts.Cancel();
var result = await task;
这篇关于如何取消CSharpScript.RunAsync的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!