-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implements OnMainThreadBlocked. #1280
base: main
Are you sure you want to change the base?
Conversation
/// <param name="cancellationToken">An optional cancellation token.</param> | ||
/// <returns>A task is completed either the slow task is completed, or the input cancellation token is triggered, or the context task blocks the main thread (inside JTF.Run).</returns> | ||
/// <exception cref="OperationCanceledException">Throw when the cancellation token is triggered or the current task blocks the main thread.</exception> | ||
public static Task WaitUnlessBlockingMainThreadAsync(this JoinableTaskContext context, Task slowTask, CancellationToken cancellationToken = default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider a slightly different signature to be similar to WithCancellation():
CancelIfMainThreadBlockedAsync(this Task slowTask, JoinableTaskContext context, CT)
That would associate it with the Task in Intellisense and imply that it throws an OperationCanceledEx like it currently does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the order of parameters suggested by Richard, and updated the PR. I would like to hear more feedback on the name of the method itself, so I haven't updated it yet.
This PR is to address #1273.
It is to allow other feature to detect whether a blocking waiting task is actually blocking the main thread. It could allow code to detect certain deadlocks (for example, blocking to wait solution loading completion but the current task is blocking the solution to load.) Or it could raise the priority of the current task in a throttling queue (like design time build queue etc).