我有一个async
我希望能够取消当前调用的方法
string html = await Html.WebClientRetryAsync(state);
我一直在尝试找出能够调用此方法并将其传递给 CancellationToken 的语法。这是我到目前为止所尝试的。
CancellationToken ct;
Func<object, Task<string>> func = async (s) => await WebClientRetryAsync((string)s);
Task<Task<string>> task = Task<Task<string>>.Factory.StartNew(func, state.Uri.AbsoluteUri, ct);
string html = await task.Result;
我计划在方法内部检查是否在继续之前请求取消。我在文档中找不到任何示例
我所拥有的不会获得该WebClientRetryAsync
方法的令牌,所以这不起作用。