dotnet / dotnet/dotnet-api-docs

The statement that "TaskFactory.ContinueWhenAll method throws an exception" is not true

Open
#2,404 0 comments 0 reactions 0 assignees View on GitHub
area-System.Threading.Tasks Pri3 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

It's said on the [CancellationToken Struct page](https://docs.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken?view=netframework-4.8#examples) that
> ...method is called to ensure that the mean is computed only after all readings have been gathered successfully. If a task has not because it has been cancelled, the call to the `TaskFactory.ContinueWhenAll` method throws an exception.

In fact, the `TaskFactory.ContinueWhenAll` method does not throw an exception but merely returns a task in any scenario. The exception is thrown on the next line where `fTask.Result` is requested:
```C#
Console.WriteLine("The mean is {0}.", fTask.Result);
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.