Skip to content

Use ContinueWith rather than finally for coroutine result types#4669

Merged
JohnMcPMS merged 1 commit intomicrosoft:masterfrom
JohnMcPMS:fix-sys-config
Jul 25, 2024
Merged

Use ContinueWith rather than finally for coroutine result types#4669
JohnMcPMS merged 1 commit intomicrosoft:masterfrom
JohnMcPMS:fix-sys-config

Conversation

@JohnMcPMS
Copy link
Member

@JohnMcPMS JohnMcPMS commented Jul 23, 2024

Issue

When run in PowerShell with MTA (multi-threaded apartment) enabled, the RunOnMTA methods have an optimization to run directly rather than spinning up a new thread. This optimization used a finally to call Complete, but a Task will be returned (and the finally executed) before the task is completed. This resulted in a completed collection and errors when attempting to add more messages to it.

Invoke-WinGetConfiguration: The collection has been marked as complete with regards to additions.

Change

Use ContinueWith and ExecuteSynchronously to effectively make a finally for the Task result object. Convert the existing finally to only call Complete on exception.

Validation

Manually confirmed the -MTA case with Invoke and Start/Complete command use cases.

Microsoft Reviewers: Open in CodeFlow

@JohnMcPMS JohnMcPMS requested a review from a team as a code owner July 23, 2024 23:55
@JohnMcPMS JohnMcPMS merged commit 414cd9a into microsoft:master Jul 25, 2024
@JohnMcPMS JohnMcPMS deleted the fix-sys-config branch July 25, 2024 20:25
DavidObando added a commit to microsoft/devcenter-catalog that referenced this pull request Jul 31, 2024
This mitigates the issue fixed by microsoft/winget-cli#4669 until that code is released.
DavidObando added a commit to microsoft/devcenter-catalog that referenced this pull request Jul 31, 2024
This mitigates the issue fixed by microsoft/winget-cli#4669 until that code is released.
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