You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The shutdown of an async external application throws after the dispatcher of the Revit thread shut down #138
Install two add-ins whose application derives from AsyncExternalApplication. OnShutdownAsync of each awaits a task that is incomplete when the method returns, for example the stop of a host.
Start Revit 2026, open a document, and exit Revit.
Seen in one of three exits of Revit 2026.5 with Nice3point.Revit.Toolkit 2026.1.4. The two other exits ended without the exception, and what shut the dispatcher down in that session is not established.
✔️ Expected Behavior
OnShutdown of an AsyncExternalApplication completes OnShutdownAsync when the dispatcher of the Revit thread has already shut down, and Revit shows no failure dialog.
❌ Actual Behavior
OnShutdown of the first add-in completes. OnShutdown of the second add-in, 13 ms later in the journal, throws from Dispatcher.PushFrame, and Revit shows External Tools - External Tool Failure for that add-in. The main window of Revit is closed at that moment.
System.InvalidOperationException: Cannot perform requested operation because the Dispatcher shut down.
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at Nice3point.Revit.Toolkit.External.AsyncExternalApplication.ExecuteAsync(Func`1 asyncMethod)
at Nice3point.Revit.Toolkit.External.AsyncExternalApplication.OnShutdown()
at Nice3point.Revit.Toolkit.External.ExternalApplication.OnShutdown(UIControlledApplication application)
at revitManagedAppShutdown()
ExecuteAsync calls Dispatcher.PushFrame for every task that is incomplete, and PushFrame throws once the dispatcher of the thread has finished its shutdown. The dispatcher was alive during the frame of the first add-in and had shut down before the frame of the second one.
In five exits of Revit 2026, the dispatcher had finished its shutdown 1.3 to 3.4 seconds before ApplicationClosing, which precedes OnShutdown.
The body also states that the dispatcher was alive during the frame of the first add-in.
That is not established either. OnShutdown pushes a frame for an incomplete task and none for a completed one, and a shutdown that returns a completed task ends without the exception in both states of the dispatcher.
The exception then depends on whether OnShutdownAsync returns an incomplete task, not on the moment the dispatcher shuts down.
This is an inference from the measurements: the three exits of the report were not reproduced.
Activity
Nice3point commentedon Nov 16, 2026
Correction
The issue body states that what shut the dispatcher down is not established.
Revit shuts it down itself:
UIFramework.MainWindow.MainWindow_UnloadedcallsDispatcher.BeginInvokeShutdown(DispatcherPriority.Normal).ApplicationClosing, which precedesOnShutdown.The body also states that the dispatcher was alive during the frame of the first add-in.
That is not established either.
OnShutdownpushes a frame for an incomplete task and none for a completed one, and a shutdown that returns a completed task ends without the exception in both states of the dispatcher.The exception then depends on whether
OnShutdownAsyncreturns an incomplete task, not on the moment the dispatcher shuts down.This is an inference from the measurements: the three exits of the report were not reproduced.