Repository navigation
[External] Complete an asynchronous shutdown after the dispatcher of the Revit thread shuts down - #139
Draft
Nice3point wants to merge 1 commit into
Draft
[External] Complete an asynchronous shutdown after the dispatcher of the Revit thread shuts down#139Nice3point wants to merge 1 commit into
Nice3point wants to merge 1 commit into
Conversation
…the Revit thread shuts down
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.
Summary of the Pull Request
What is this about:
Completes
OnShutdownAsyncof an asynchronous external application after Revit shuts down the WPF dispatcher of its thread.Description:
What changed
AsyncExternalApplicationandAsyncExternalCommandwait for their task through one internalMessagePump.Run.DispatcherFrameexitWhenRequested: falseand continues until the task completesDispatcher.PushFramethrowsInvalidOperationExceptionSynchronizationContextthat queues the continuations, and restores the previous context when the task completes.MsgWaitForMultipleObjectsExandPeekMessage.WM_QUITmessage removed during the wait is posted again with its exit code.OnShutdownAsync, the changelog, and therevit-toolkit-internalsskill describe both states of the dispatcher.Where to look
UIFramework.MainWindow.MainWindow_UnloadedcallsDispatcher.BeginInvokeShutdown. In five exits of Revit 2026, the shutdown had finished beforeApplicationClosing.WindowsFormsSynchronizationContext, which delivers a continuation as a window message, and a blocking wait never receives it.Dispatcher.ExitAllFrames()as well as the shutdown request. The dispatcher finishes its shutdown when the frame exits.NotSupportedExceptionfor aSendfrom another thread, and never runs a callback posted after the asynchronous method completes.2027.0.5section. The build settings still state2027.0.4.How verified
Release.R20,Release.R24, andRelease.R27, and the tests onDebug.R24,Debug.R26, andDebug.R27, zero errors and no new warnings.AsyncExternalApplicationTests, 9 passed.ApplicationClosinghandler of Revit 2026 ran the same wait after the dispatcher shut down: the previous wait threw the exception of the issue, and the pump completed with the continuations on the Revit thread.Open questions
WM_QUITmessage that arrives during the frame of a running dispatcher ends the frame before the task completes, and the wait after it blocks. No session showed this case, and the change leaves it as it is.Quality Checklist