Task 超时取消
using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(3)))
{
// cts.CancelAfter(TimeSpan.FromSeconds(3));
try
{
var token = cts.Token;
await Task.Delay(5000, token);
}
catch (Exception e)
{
if (e is TaskCanceledException te)
{
}
}
}
努力到无能为力,拼搏到感动自己