2017-04-18 07:52:04 +08:00
## Change in behavior for Task.WaitAll methods with time-out arguments
2017-04-06 04:52:19 +08:00
### Scope
Minor
### Version Introduced
4.5
### Source Analyzer Status
Available
### Change Description
2017-04-21 02:19:05 +08:00
Task.WaitAll behavior was made more consistent in .NET 4.5.
In the .NET Framework 4, these methods behaved inconsistently. When the time-out
expired, if one or more tasks were completed or canceled before the method call,
the method threw an < xref:System.AggregateException ? displayProperty = name >
exception. When the time-out expired, if no tasks were completed or canceled
before the method call, but one or more tasks entered these states after the
method call, the method returned false.< br / > < br / > In the .NET Framework 4.5,
these method overloads now return false if any tasks are still running when the
time-out interval expired, and they throw an
< xref:System.AggregateException ? displayProperty = name > exception only if an input
task was cancelled (regardless of whether it was before or after the method
call) and no other tasks are still running.
2017-04-06 04:52:19 +08:00
- [ ] Quirked
- [ ] Build-time break
### Recommended Action
2017-04-21 02:19:05 +08:00
If an < xref:System.AggregateException ? displayProperty = name > was being caught as a means of detecting a task that was cancelled prior to the WaitAll call being invoked, that code should instead do the same detection via the IsCanceled property (for example: .Any(t => t.IsCanceled)) since .NET 4.6 will only throw in that case if all awaited tasks are completed prior to the timeout.
2017-04-06 04:52:19 +08:00
### Affected APIs
* `M:System.Threading.Tasks.Task.WaitAll(System.Threading.Tasks.Task[],System.Int32)`
* `M:System.Threading.Tasks.Task.WaitAll(System.Threading.Tasks.Task[],System.Int32,System.Threading.CancellationToken)`
* `M:System.Threading.Tasks.Task.WaitAll(System.Threading.Tasks.Task[],System.TimeSpan)`
### Category
Core
2017-04-18 07:52:04 +08:00
<!-- breaking change id: 26 -->