Skip to content

Conversation

@AlexanderSher
Copy link
Contributor

In release builds, correctly wait for the value task synchronously if it runs without sync context or task scheduler, otherwise throw (#11855 (comment))

#if DEBUG
VerifyTaskCompleted(task.IsCompleted);
#else
if (HasSynchronizationContext())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is worth doing. Might break customers apps that worked just fine before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may for some custom non-blocking sync context. In that case, they will report a bug and use Task.Run as a workaround while we fix it. However, if we don't throw in this case, the most common sync context scenario of interaction with UI will hang without any clue for the user why it has happened.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is of course if we have any bugs like that at all (this exception should be thrown only if we have sync code that waits on incomplete task while should only get the result of completed).

@pakrym
Copy link
Contributor

pakrym commented Jul 27, 2020

Do you think it's worth adding tests?

@AlexanderSher AlexanderSher merged commit 49bcc3e into Azure:master Jul 28, 2020
AlexanderSher added a commit to AlexanderSher/azure-sdk-for-net that referenced this pull request Aug 18, 2020
AlexanderSher added a commit that referenced this pull request Aug 18, 2020
…#13719)" (#14306)

* Revert "Fix #10904: Task extensions synchronously complete ValueTasks (#13719)"

This reverts commit 49bcc3e.

* Fix changelog and csproj

* Revert csproj change

* Update changelog
@AlexanderSher AlexanderSher deleted the Fix10904 branch August 24, 2020 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants