Add JoinableTaskFactory.DisableProcessing() - #1576
Merged
Merged
Conversation
Andrew Arnott (AArnott)
requested review from
Copilot,
David Kean (davkean),
kayle and
Lifeng Lu (lifengl)
April 22, 2026 18:55
There was a problem hiding this comment.
Pull request overview
Adds a JoinableTaskFactory.DisableProcessing() API to suppress message pumping (e.g., COM RPC reentrancy via CoWait) during synchronous waits within the ambient JoinableTask, plus tests and samples demonstrating the behavior.
Changes:
- Introduce
JoinableTaskFactory.DisableProcessing()and plumb aDisableProcessingflag throughJoinableTaskand its synchronization context’sWaitoverride. - Add .NET Framework STA tests and a COM-based probe (
CoWaitMainThreadTransition) to validate CoWait penetration vs. blocking behavior. - Update samples/docs wiring (new DisableProcessing sample, SuppressRelevance sample ref update) and bump version.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| version.json | Bumps package version to 18.7. |
| test/Microsoft.VisualStudio.Threading.Tests/NonConcurrentSynchronizationContextTests.cs | Adjusts tuple nullability in an existing test. |
| test/Microsoft.VisualStudio.Threading.Tests/NoMessagePumpSyncContextTests.cs | Adds STA tests validating no-message-pump waits (NETFRAMEWORK only). |
| test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskFactoryTests.cs | Adds tests for DisableProcessing() behavior and nesting. |
| test/Microsoft.VisualStudio.Threading.Tests/CoWaitMainThreadTransition.cs | Adds a COM-based probe to detect whether CoWait/message pumping occurs (NETFRAMEWORK only). |
| test/Microsoft.VisualStudio.Threading.Tests/AsyncCrossProcessMutexTests.cs | Tweaks abandoned-mutex assertions in TryEnterAsync_AbandonedMutex. |
| src/Microsoft.VisualStudio.Threading/Strings.resx | Adds NoAmbientTask resource string for the new API exception. |
| src/Microsoft.VisualStudio.Threading/ReentrantSemaphore.cs | Updates sample code reference for SuppressRelevance. |
| src/Microsoft.VisualStudio.Threading/NoMessagePumpSyncContext.cs | Refines OS/runtime conditional compilation for Windows detection. |
| src/Microsoft.VisualStudio.Threading/JoinableTaskFactory.cs | Adds DisableProcessing() public API and ProcessingDisabledOperation token. |
| src/Microsoft.VisualStudio.Threading/JoinableTask.cs | Adds internal DisableProcessing flag and sync context propagation. |
| src/Microsoft.VisualStudio.Threading/JoinableTask+JoinableTaskSynchronizationContext.cs | Adds DisableProcessing support and overrides Wait to use WaitForMultipleObjects when enabled. |
| samples/SuppressRelevance.cs | Renames sample type and fixes a spelling error in a comment. |
| samples/Polyfill.cs | Adds NETFRAMEWORK polyfill stub used by samples. |
| samples/DisableProcessing.cs | Adds new sample referenced by the new API docs. |
| .github/copilot-instructions.md | Clarifies namespace expectations for new files vs. test files. |
Andrew Arnott (AArnott)
force-pushed
the
dev/andarno/disableProcessing
branch
from
April 22, 2026 19:37
701e9e7 to
5812af0
Compare
kayle
reviewed
Apr 22, 2026
kayle
reviewed
Apr 22, 2026
kayle
approved these changes
Apr 22, 2026
This method is like the WPF `Dispatcher.DisableProcessing()` method, except that it impacts the `SynchronizationContext` that `JoinableTask` delegates execute within. As part of this, I introduce a test helper class for actually testing the penetrability of sync blocks so we can adequately test this new API. Since this test helper also can apply to `NoMessagePumpSyncContext` testing (which did not exist), I added new tests for that class too.
Andrew Arnott (AArnott)
force-pushed
the
dev/andarno/disableProcessing
branch
from
April 22, 2026 20:12
5812af0 to
c1a7f7c
Compare
Andrew Arnott (AArnott)
force-pushed
the
dev/andarno/disableProcessing
branch
from
April 22, 2026 21:27
3869f31 to
a7d1c6f
Compare
…`JoinableTaskFactory`-derived types
Andrew Arnott (AArnott)
force-pushed
the
dev/andarno/disableProcessing
branch
from
April 22, 2026 21:29
a7d1c6f to
1613479
Compare
…child JoinableTasks
kayle
approved these changes
Apr 23, 2026
Andrew Arnott (AArnott)
enabled auto-merge
April 23, 2026 15:01
This was referenced Jul 30, 2026
James Gunn (gunndabad)
pushed a commit
to DFE-Digital/teaching-record-system
that referenced
this pull request
Aug 7, 2026
….23 (#3704) Updated [Microsoft.VisualStudio.Threading.Analyzers](https://github.com/microsoft/vs-threading) from 17.14.15 to 18.7.23. <details> <summary>Release notes</summary> _Sourced from [Microsoft.VisualStudio.Threading.Analyzers's releases](https://github.com/microsoft/vs-threading/releases)._ ## 18.7.23 ## What's Changed ### Fixes * Fix `CancellationToken.Combine` with 3+ cancelable tokens by @AArnott in microsoft/vs-threading#1443 * Fix VSTHRD110 firing in Expression-valued scenarios by @AArnott with @Copilot in microsoft/vs-threading#1467 * Fix super set for VSTHRD103 by @AArnott in microsoft/vs-threading#1545 * Fix VSTHRD114 not firing for null in ternary conditional expressions by @AArnott with @Copilot in microsoft/vs-threading#1548 * Disable VSTHRD010 in AppWithoutMainThread.editorconfig by @ArturDorochowicz in microsoft/vs-threading#1562 * Fix VSTHRD103 missing diagnostic for sync extension methods with async alternatives in the same static class by @drewnoakes with @Copilot in microsoft/vs-threading#1569 ### Enhancements * Add `JoinableTaskFactory.DisableProcessing()` by @AArnott in microsoft/vs-threading#1576 * Add `NoMessagePumpSyncContext..ctor(SynchronizationContext)` for Post/Send behaviors by @AArnott in microsoft/vs-threading#1578 * Add trim and NativeAOT safety attributes by @AArnott in microsoft/vs-threading#1471 * Add `IPendingExecutionRequestState` interface to expose completion state of `SingleExecuteProtector` by @lifengl in microsoft/vs-threading#1447 * Add AdditionalFiles support to VSTHRD103 analyzer for excluding specific APIs by @AArnott with @Copilot in microsoft/vs-threading#1465 * Document InvalidOperationException for AsyncReaderWriterLock acquisition methods by @AArnott with @Copilot in microsoft/vs-threading#1466 * Allow library code to detect the JoinableTaskContext is not associated with Main thread by @lifengl in microsoft/vs-threading#1477 * remove NotifyOfCrossThreadDependency call inside get_NoMessagePumpSynchronizationContext by @lifengl in microsoft/vs-threading#1486 * reduce overhead when running in no main thread mode by @lifengl in microsoft/vs-threading#1502 * Join tasks waited by JoinableTaskCollection.JoinUntilEmpty in dumpasync result by @lifengl in microsoft/vs-threading#1538 * Remove slow regex from threading analyzers by @AArnott in microsoft/vs-threading#1547 ## New Contributors * @jgrosic made their first contribution in microsoft/vs-threading#1485 * @AbhitejJohn made their first contribution in microsoft/vs-threading#1533 * @ArturDorochowicz made their first contribution in microsoft/vs-threading#1562 * @microsoft-github-policy-service[bot] made their first contribution in microsoft/vs-threading#1587 **Full Changelog**: microsoft/vs-threading@v17.14.15...v18.7.23 Commits viewable in [compare view](microsoft/vs-threading@v17.14.15...v18.7.23). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This was referenced Aug 7, 2026
This was referenced Aug 15, 2026
Closed
This was referenced Aug 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sample use case:
This also enhances the
JoinableTaskFactory.WithPriority(Dispatcher)extension method so that it automatically honors calls toDispatcher.DisableProcessing()to match its behavior.