1

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.

Community
  • 1
  • 1
Relativity
  • 6,690
  • 22
  • 78
  • 128

1 Answers1

0

You can create a custom mini-console app that doesn't have a close button to run your server program. Nice snippet is found in an answer for this question.

Community
  • 1
  • 1
takashi
  • 1
  • 1