A console process has its own list of application-defined HandlerRoutine functions that handle CTRL+C and CTRL+BREAK signals. The handler functions also handle signals generated by the system when the user closes the console, logs off, or shuts down the system.
TestCon looks at CtRL-C signals. At startup, a ControlHandler is setup by the TestCon host app to watch for Shutdown requests of the following types
private static bool ControlHandler(Win32.ConsoleControlEventType ctrlType)
{
switch (ctrlType)
{
case Win32.ConsoleControlEventType.CtrlC:
case Win32.ConsoleControlEventType.CtrlBreak:
case Win32.ConsoleControlEventType.CtrlClose:
case Win32.ConsoleControlEventType.CtrlLogoff:
case Win32.ConsoleControlEventType.CtrlShutdown:
if (mProgram.mVSTAHookup != null)
{
mProgram.mVSTAHookup.StopVSTA();
mProgram.mVSTAHookup = null;
}
break;
}
return false;
}
...making sure that mVSTAHookup is released.
As well, there is a public method exposed that allows the addin to shutdown in an orderly way, also making sure that mVSTAHookup is released:
public void ShutDown()
{
if (mVSTAHookup != null)
{
if (mDesignTime && mVSTAHookup.IsDTEVisible())
{
mVSTAHookup.StopDebugging();
}
else
{
mVSTAHookup.StopVSTA();
mVSTAHookup = null;
ReleaseControlHandler();
}
}
}