我正在使用此代码片段执行带有取消令牌的异步查询:
var _client = new HttpClient( /* some setthngs */ );
_client.GetAsync(someUrl, cancellationToken).ContinueWith(gettingTask => {
cancellationToken.ThrowIfCancellationRequested();
SomeStuffToDO();
}, TaskScheduler.FromCurrentSynchronizationContext());
}, TaskScheduler.FromCurrentSynchronizationContext());
但是,当操作被取消时,cancellationToken.ThrowIfCancellationRequested();
会引发异常。我知道这条线应该是这个东西。但是,在开发环境中,异常会导致视觉工作室中断。我怎样才能避免这种情况?