Skip to content

Conversation

@Youssef1313
Copy link
Member

Fixes #5729

@Evangelink Evangelink enabled auto-merge January 12, 2026 21:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a UseSTASynchronizationContext property to STATestMethodAttribute to enable preserving the STA thread context for async continuations. When enabled, the attribute creates a custom SynchronizationContext that ensures async continuations run on the same STA thread, which is useful for testing UI components that require STA threading.

Changes:

  • Introduced SingleThreadedSTASynchronizationContext class that manages a dedicated STA thread and routes all operations to it
  • Added UseSTASynchronizationContext property to STATestMethodAttribute with default value of false
  • Modified STATestMethodAttribute.ExecuteAsync to conditionally use the new synchronization context
  • Added tests to verify both default behavior (no sync context) and new behavior (with sync context)

Reviewed changes

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

File Description
src/TestFramework/TestFramework/Attributes/TestMethod/SingleThreadedSTASynchronizationContext.cs New internal class that implements a custom SynchronizationContext with a dedicated STA thread for routing operations
src/TestFramework/TestFramework/Attributes/TestMethod/STATestMethodAttribute.cs Added UseSTASynchronizationContext property and modified ExecuteAsync to optionally use the new sync context
src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt Added public API entries for the new property getter and setter
test/UnitTests/MSTest.SelfRealExamples.UnitTests/STATestMethodSyncContext.cs Added integration tests verifying both default and new behavior

Copy link
Contributor

Copilot AI left a comment

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 4 out of 4 changed files in this pull request and generated 4 comments.

@Evangelink Evangelink merged commit 2462bf5 into main Jan 14, 2026
15 of 16 checks passed
@Evangelink Evangelink deleted the dev/ygerges/sta branch January 14, 2026 10:48
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.

STA-Thread lost after async operation

4 participants