Prevent console close

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.
 
L

Lau Lei Cheong

Add a call to the following calls at the end.
Console.Write("Press enter to continue...");
Console.ReadLine() ;
 
L

Lau Lei Cheong

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?"
 
J

Jeroen Vandezande

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top