作者:wo1344165221 | 来源:互联网 | 2023-05-25 18:42
1> kiewic..:
使用CancellationToken
:
try
{
CancellationTokenSource cts = new CancellationTokenSource(2000); // 2 seconds
HttpClient client = new HttpClient();
HttpResponseMessage respOnse= await
client.SendRequestAsync(request).AsTask(cts.Token);
}
catch (TaskCanceledException ex)
{
// Catch operation aborted ...
}