I have two console applications : client and server (server is self hosted wcf service).
multiple clients can connect to same server.
If user click X button of server console...and if number of clients connected to that server is > 0, it should not close.
I tried code available here Capture console exit C#...and changed handler as below.
private static bool Handler(CtrlType sig)
{
if (CanCloseServer())
{
exitSystem = true;
//shutdown right away so there are no lingering threads
//Environment.Exit(0);
return true;
}
return false;
}
It still closes the window (reason I think is windows close command is uninterrupted even now). Could someone tell me how can I cancel the X event please.