Thanks in advance for your assistance!!!
System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess();
process.Exited += new EventHandler(OnExited);
// Note, you may also want to dispose of the "process" object when the event is fired.
--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"Jim Heavey" <JimH...@discussions.microsoft.com> wrote in message news:5A1EF80F-3DD8-4E5F...@microsoft.com...
I would suggest you to install a Console Control handler that catches the
Console Close event.
enum CtrlType {
CTRL_C_EVENT = 0,
CTRL_BREAK_EVENT = 1,
CTRL_CLOSE_EVENT = 2,
CTRL_LOGOFF_EVENT = 5,
CTRL_SHUTDOWN_EVENT = 6
}
private delegate bool EventHandler(CtrlType sig);
// Sample Console CTRL handler
private static bool Handler(CtrlType sig)
{
bool handled = false;
switch (sig)
{
case CtrlType.CTRL_C_EVENT:
case CtrlType.CTRL_LOGOFF_EVENT:
case CtrlType.CTRL_SHUTDOWN_EVENT:
case CtrlType.CTRL_CLOSE_EVENT:
{
// Clean-up code goes here
}
// return false if you want the process to exit.
// returning true, causes the system to display a dialog
// giving the user the choice to terminate or continue
handled = true;
break;
default:
return handled;
}
return handled;
}
[DllImport("Kernel32")]
private static extern bool SetConsoleCtrlHandler (EventHandler handler,
bool add);
..in Main()...
// Install handler
_handler += new EventHandler(Handler);
SetConsoleCtrlHandler(_handler, true);
...
Willy.