How to handle a c # console application?

If I have a console application, can I handle the following:

  • Ctrl-C (I know the answer to this question. Using Console.TreatControlCAsInput and Console.CancelKeyPress)
  • Terminating a session, for example, when someone logs out
  • A process exit, for example, when someone uses a task manager to close an application.

I know that if I were writing a unix application, I would process various signals to catch a close request (SIGTERM from memory), but I also know that I need to quickly process these messages and exit before the system executes kill - 9 (SIGKILL).

But for a C # console application, I'm not sure how to do this.

+5
source share
1

, , -

SystemEvents.SessionEnded.

, , - .

, - , , .

+4

All Articles