Prevent console close

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a console application.
I need to prevent the user from closing the application by closing the
console window. Is there a way to do that? Maybe to catch the console close
event and cancel it?
Please if there is a way tell me how to do that.

Thanks.
 
Add a call to the following calls at the end.
Console.Write("Press enter to continue...");
Console.ReadLine() ;
 
Oops... I misread your question.

The fact is, your console application has no control on when the shell
(hence the window contains it) terminates. So you can't stop that.

Your question sounds analogic to "Whether I can keep my program running if
someone shutdowns Windows?"
 
barbutz said:
Hi,

I have a console application.
I need to prevent the user from closing the application by closing the
console window. Is there a way to do that? Maybe to catch the console
close
event and cancel it?
Please if there is a way tell me how to do that.


Hi,

Like the other poster said: you don't have control over the console
window...
If it is that important you should concider making the console app into a
service application.
unless you do a lot of user IO it should not be a problem to do so.


Best Regards,

Jeroen Vandezande
 
Back
Top