[Enhancement] Use TaskCreationOptions.RunContinuationsAsynchronously when creating a TaskCompletionSource
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 290
Description
From [this guide](https://github.com/davidfowl/AspNetCoreDiagnosticScenarios/blob/master/AsyncGuidance.md#always-create-taskcompletionsourcet-with-taskcreationoptionsruncontinuationsasynchronously) would be good if all `TaskCompletionSource` used in MAUI have the `TaskCreationOptions.RunContinuationsAsynchronously` in his constructor, this will avoid dead-locks.
```csharp
// Instead of doing this
var tcs = new TaskCompletionSource();
// do this
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
```
From the guide:
> Always use TaskCreationOptions.RunContinuationsAsynchronously when creating the TaskCompletionSource. This will dispatch the continuation onto the thread pool instead of executing it inline.
Since .NET MAUI is a UI framework this will need some investigation to see if there's any problem with that, in other words, risk of trying to change some UI control in `non-MainThread`.
Contributor guide
Research direction
Search the MAUI repository for every TaskCompletionSource construction and identify the affected platform-specific and shared code paths. Review the linked AsyncGuidance guidance and verify that applying the option does not cause UI updates from a non-main thread; done means the relevant usages are updated and the existing tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop, mobile
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100