我在查看我的旧项目的代码时发现:
private async void send(HttpRequestMessage request, CancellationToken cancellationToken)
{
HttpResponseMessage response = await _client.SendAsync(request, cancellationToken);
//...
}我想知道取消的时候会发生什么?
会有什么反应?
在此之后,我是否需要调用ThrowIfCancellationRequested,还是它本身会引发异常?
发布于 2016-09-25 11:11:26
发布于 2016-09-25 10:48:26
你得这样称呼它
...
cancelToken.ThrowIfCancellationRequested();
HttpResponseMessage response = await _client.SendAsync(request, cancellationToken);
...然后,当您请求取消时,它将抛出OperationCanceledException类型的异常。
https://stackoverflow.com/questions/39685965
复制相似问题