Skip to content
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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

lifengl
Copy link
Member

@lifengl lifengl commented Feb 5, 2024

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).

/// <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)
Copy link
Member

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.

Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants