fix: queue native quit after automation commands
This commit is contained in:
@@ -287,9 +287,10 @@ internal sealed class FirstLimitedApplyAutomationCoordinator
|
||||
RequestControlledExit(safeToExitNow);
|
||||
}
|
||||
|
||||
// AutoCAD's direct Application.Quit can leave a startup-script host alive.
|
||||
// Dispatching the native QUIT command from the next quiescent Idle cycle
|
||||
// preserves normal command shutdown semantics.
|
||||
// The managed Application.Quit call can leave a startup-script host alive
|
||||
// when it is invoked from a CommandEnded callback. Queue AutoCAD's native
|
||||
// QUIT command instead; the command processor runs it after the current
|
||||
// public PXP-OA command has fully returned and discards every open drawing.
|
||||
private void RequestControlledExit(bool idleSafe = false)
|
||||
{
|
||||
if (exitQueued) return;
|
||||
@@ -315,21 +316,14 @@ internal sealed class FirstLimitedApplyAutomationCoordinator
|
||||
{
|
||||
if (exitHandlerSubscribed) AcadApplication.Idle -= OnExitIdle;
|
||||
exitHandlerSubscribed = false;
|
||||
// Do not close a cached automation document and then reuse it. Resolve
|
||||
// the currently-live document only at the final quiescent callback.
|
||||
// Only documents opened by this coordinator may be closed. Keep no
|
||||
// document reference after closing it; DocumentDestroyed can run
|
||||
// immediately as part of CloseAndDiscard.
|
||||
foreach (var opened in automationOpenedDocuments.ToArray().Reverse())
|
||||
{
|
||||
transitions.Add("AutomationDocumentCloseRequested");
|
||||
opened.CloseAndDiscard();
|
||||
}
|
||||
if (document is null) throw new InvalidOperationException("AUTOMATION_EXIT_DOCUMENT_UNAVAILABLE");
|
||||
transitions.Add("NativeQuitCommandQueued");
|
||||
// Persist the exit boundary before handing control back to AutoCAD;
|
||||
// process termination can otherwise prevent the final evidence flush.
|
||||
TryWriteEvidence(state == CoordinatorState.Completed, null);
|
||||
document.SendStringToExecute("_.QUIT _N ", true, false, false);
|
||||
document = null;
|
||||
automationOpenedDocuments.Clear();
|
||||
// Application.Quit alone leaves the script host alive. Close the
|
||||
// live document first, then request normal application shutdown.
|
||||
transitions.Add("ApplicationQuitRequested");
|
||||
AcadApplication.Quit();
|
||||
}
|
||||
catch (System.Exception exception)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user