Skip to content

Add JoinableTaskFactory.DisableProcessing() - #1576

Merged
Andrew Arnott (AArnott) merged 5 commits into
mainfrom
dev/andarno/disableProcessing
Apr 23, 2026
Merged

Add JoinableTaskFactory.DisableProcessing()#1576
Andrew Arnott (AArnott) merged 5 commits into
mainfrom
dev/andarno/disableProcessing

Conversation

@AArnott

@AArnott Andrew Arnott (AArnott) commented Apr 22, 2026

Copy link
Copy Markdown
Member

Sample use case:

jtf.Run(
    async delegate
    {
        jtf.DisableProcessing();
        // Code that cannot afford to be interrupted by COM RPC calls during synchronously blocking calls.
    });

This also enhances the JoinableTaskFactory.WithPriority(Dispatcher) extension method so that it automatically honors calls to Dispatcher.DisableProcessing() to match its behavior.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 a DisableProcessing flag through JoinableTask and its synchronization context’s Wait override.
  • 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.

Comment thread samples/Polyfill.cs
Comment thread src/Microsoft.VisualStudio.Threading/JoinableTaskFactory.cs
Copilot AI review requested due to automatic review settings April 22, 2026 19:37
@AArnott
Andrew Arnott (AArnott) force-pushed the dev/andarno/disableProcessing branch from 701e9e7 to 5812af0 Compare April 22, 2026 19:37
Comment thread samples/DisableProcessing.cs

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

Comment thread src/Microsoft.VisualStudio.Threading/JoinableTaskFactory.cs
Comment thread src/Microsoft.VisualStudio.Threading/JoinableTaskFactory.cs Outdated
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.
@AArnott
Andrew Arnott (AArnott) force-pushed the dev/andarno/disableProcessing branch from 5812af0 to c1a7f7c Compare April 22, 2026 20:12
Copilot AI review requested due to automatic review settings April 22, 2026 21:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.

Comment thread src/Microsoft.VisualStudio.Threading/JoinableTaskFactory.cs Outdated
@AArnott
Andrew Arnott (AArnott) force-pushed the dev/andarno/disableProcessing branch from 3869f31 to a7d1c6f Compare April 22, 2026 21:27
@AArnott
Andrew Arnott (AArnott) force-pushed the dev/andarno/disableProcessing branch from a7d1c6f to 1613479 Compare April 22, 2026 21:29
Copilot AI review requested due to automatic review settings April 23, 2026 14:49
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>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=Microsoft.VisualStudio.Threading.Analyzers&package-manager=nuget&previous-version=17.14.15&new-version=18.7.23)](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>
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.

3 participants