AsyncWorkerCollection
AsyncWorkerCollection copied to clipboard
AsyncAutoResetEvent能指定等待时间吗?
如题,用Task.Wait的话又失去了async的意义
用这种方式是否可行? https://stackoverflow.com/a/11191070/10231865
int timeout = 1000;
var task = SomeOperationAsync(cancellationToken);
if (await Task.WhenAny(task, Task.Delay(timeout, cancellationToken)) == task)
{
// Task completed within timeout.
// Consider that the task may have faulted or been canceled.
// We re-await the task so that any exceptions/cancellation is rethrown.
await task;
}
else
{
// timeout/cancellation logic
}
@yll690 可以呀