fix: close live document before automation exit
This commit is contained in:
@@ -316,9 +316,15 @@ internal sealed class FirstLimitedApplyAutomationCoordinator
|
|||||||
// Do not close a cached automation document and then reuse it. Resolve
|
// Do not close a cached automation document and then reuse it. Resolve
|
||||||
// the currently-live document only at the final quiescent callback.
|
// the currently-live document only at the final quiescent callback.
|
||||||
var active = AcadApplication.DocumentManager.MdiActiveDocument;
|
var active = AcadApplication.DocumentManager.MdiActiveDocument;
|
||||||
if (active is null) { AcadApplication.Quit(); return; }
|
if (active is not null)
|
||||||
transitions.Add("NativeQuitDispatched");
|
{
|
||||||
active.SendStringToExecute("_.QUIT _N ", true, false, false);
|
transitions.Add("ActiveDocumentCloseRequested");
|
||||||
|
active.CloseAndDiscard();
|
||||||
|
}
|
||||||
|
// 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)
|
catch (System.Exception exception)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -82,12 +82,13 @@ public sealed class FoundationTests
|
|||||||
Assert.Contains("PostStartupReady", source);
|
Assert.Contains("PostStartupReady", source);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact] public void AutomationControlledExit_UsesNativeQuitFromIdle()
|
[Fact] public void AutomationControlledExit_ClosesLiveDocumentThenQuitsFromIdle()
|
||||||
{
|
{
|
||||||
var source = File.ReadAllText(Path.Combine(ProjectRoot, "src", "PRecAnnot.Plant3D2026", "FirstLimitedApplyAutomation.cs"));
|
var source = File.ReadAllText(Path.Combine(ProjectRoot, "src", "PRecAnnot.Plant3D2026", "FirstLimitedApplyAutomation.cs"));
|
||||||
Assert.Contains("RequestControlledExit", source);
|
Assert.Contains("RequestControlledExit", source);
|
||||||
Assert.Contains("AcadApplication.Idle += OnExitIdle", source);
|
Assert.Contains("AcadApplication.Idle += OnExitIdle", source);
|
||||||
Assert.Contains("active.SendStringToExecute(\"_.QUIT _N \", true, false, false)", source);
|
Assert.Contains("active.CloseAndDiscard();", source);
|
||||||
|
Assert.Contains("AcadApplication.Quit();", source);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact] public void Callback_AfterDocumentDestroyed_DoesNotAccessDocument()
|
[Fact] public void Callback_AfterDocumentDestroyed_DoesNotAccessDocument()
|
||||||
@@ -100,7 +101,8 @@ public sealed class FoundationTests
|
|||||||
[Fact] public void Idle_WhenActiveDocumentNull_DoesNotThrow()
|
[Fact] public void Idle_WhenActiveDocumentNull_DoesNotThrow()
|
||||||
{
|
{
|
||||||
var source = File.ReadAllText(Path.Combine(ProjectRoot, "src", "PRecAnnot.Plant3D2026", "FirstLimitedApplyAutomation.cs"));
|
var source = File.ReadAllText(Path.Combine(ProjectRoot, "src", "PRecAnnot.Plant3D2026", "FirstLimitedApplyAutomation.cs"));
|
||||||
Assert.Contains("if (active is null) { AcadApplication.Quit(); return; }", source);
|
Assert.Contains("if (active is not null)", source);
|
||||||
|
Assert.Contains("AcadApplication.Quit();", source);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact] public void TerminalState_IgnoresFurtherCallbacks()
|
[Fact] public void TerminalState_IgnoresFurtherCallbacks()
|
||||||
|
|||||||
Reference in New Issue
Block a user