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

Add an overload to SwitchToMainThreadAsync that exposes 'alwaysYield' #340

Merged
merged 1 commit into from
Aug 8, 2018

Conversation

sharwell
Copy link
Member

@sharwell sharwell commented Aug 6, 2018

Fixes #326

@sharwell sharwell force-pushed the support-always-yield branch from 3cf348a to e9fe7a7 Compare August 6, 2018 03:13
/// await TaskScheduler.Default;
///
/// // Now switch to the Main thread to talk to some STA object.
/// await this.JobContext.SwitchToMainThreadAsync(alwaysYield: true);
Copy link
Member

Choose a reason for hiding this comment

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

This sample isn't particularly compelling because it will always yield anyway. Can you include a sample that demonstrates when it would be interesting to use this overload? (at least that's already on the main thread or in an ambiguous state)?

Copy link
Member Author

Choose a reason for hiding this comment

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

💭 A compelling example would be great. I actually prefer to not use this in favor of either alwaysYield: false (default behavior) or Task.Yield (always yield, but stay on current thread). This method's primary advantage is supporting the incremental conversion of code using SynchronizationContext.Post or other "always yield" methods to vs-threading.

Copy link
Member

Choose a reason for hiding this comment

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

I've updated the sample. Since I don't have permission to push to your source branch, I'll complete the PR with my commit on top locally.

@AArnott AArnott merged commit e9fe7a7 into microsoft:master Aug 8, 2018
AArnott added a commit that referenced this pull request Aug 8, 2018
Add an overload to SwitchToMainThreadAsync that exposes 'alwaysYield'
@AArnott AArnott added this to the v16.0 milestone Aug 8, 2018
@sharwell sharwell deleted the support-always-yield branch August 8, 2018 17:02
AArnott pushed a commit that referenced this pull request Jan 15, 2025
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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.

2 participants