dotnet / dotnet/dotnet-api-docs
WaitAny / WhenAny
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
The document implies that WaitAny needs to be wrapped in a try/catch. This is an error.
Code example:
var t = Task.Run(() => (1 == 1) ? throw new Exception(“good exception”) : 2);
var r = Task.WaitAny(new Task<int>[] { t }).Unwrap(); // no exception thrown
try
{
var i = r.Result;
Console.WriteLine(“all is well”);
}
catch (AggregateException ae)
{
var fe = ae.Flatten();
foreach (var e in fe.InnerExceptions)
Console.WriteLine($”Exception: {e.Message}”);
}
---
#### Document Details
⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*
* ID: d5070e2d-4c1d-ae9c-6b7c-6becf1703f32
* Version Independent ID: ae444bfa-9eb2-d546-71ed-cede0eccea08
* Content: [WaitHandle.WaitAny Method (System.Threading)](https://docs.microsoft.com/en-us/dotnet/api/system.threading.waithandle.waitany?view=netframework-4.7.2)
* Content Source: [xml/System.Threading/WaitHandle.xml](https://github.com/dotnet/dotnet-api-docs/blob/master/xml/System.Threading/WaitHandle.xml)
* Product: **dotnet-api**
* GitHub Login: @dotnet-bot
* Microsoft Alias: **dotnetcontent**
Contributor guide
Assessment
This issue has not been assessed yet.