CloseConsoleEmulator Briefly Shows the Hidden Console
To reproduce, run the ControlDllTestbed project, it would open a terminal on startup, now press the Choice button. This kills the active terminal in the control and spawns a new one. The old one briefly appears as a large window.
The code executed is:
if(!_process.HasExited)
BeginGuiMacro("Close").WithParam(1 /*terminate active process*/).WithParam(1 /*without confirmation*/).ExecuteSync();
if(!_process.HasExited)
_process.Kill();
So it sends ConEmu a graceful request, waits for the GuiMacro to complete executing, and then kills the process in case it still has failed to process the graceful request (as we want to be 100% sure not to leave stale processes behind, especially in a long-running app).
Interestingly, if the last Kill line is removed, then it closes smoothly. But I believe the code should try to be as reliable as possible, so the Kill is nice to have there.
Is it that the GuiMacro exits before completing the work fully? Can it be adjusted?
cc @Maximus5
You terminate only active process. So there may be large lag while a) all console processes are terminated too (if they even are to) b) server process realizes that and terminates in turn. Until than, if GUI is terminated - real console is revealed.
The only correct way to close console is Close(0,1).
Changed it to be
if(!_process.HasExited)
BeginGuiMacro("Close").WithParam(0 /*terminate whole console*/).WithParam(1 /*without confirmation*/).ExecuteSync();
if(!_process.HasExited)
_process.Kill();
no much difference.