[DllImport("kernel32.dll", SetLastError = true)]
static extern uint GetConsoleProcessList(
uint[] ProcessList,
uint ProcessCount
);
Declare Function GetConsoleProcessList Lib "kernel32.dll" (TODO) As TODO
None.
Do you know one? Please contribute it!
To determine if the console will be destroyed when your application exits, check if (processCount < 2). For example:
public static bool IsFinalProcess()
{
// See: https://devblogs.microsoft.com/oldnewthing/20160125-00/?p=92922
uint[] procIDs = new uint[64];
uint processCount = GetConsoleProcessList(procIDs, 64);
return (processCount < 2);
}
Check IsFinalProcess() as your application exits. If true, use Console.ReadKey(false); to prevent the window disappearing.
uint[] procIDs = new uint[64];
uint processCount = GetConsoleProcessList(procIDs, 64);