Stop a Console App from exiting?

  • Thread starter Thread starter Terry Olsen
  • Start date Start date
T

Terry Olsen

I've used the following suggestion from one of the MVP's here:
'Add a reference to 'System.Windows.Forms.dll', import the
''System.Windows.Forms' namespace, and call 'Application.Run' at the end of
'your 'Sub Main'. Then you can call 'Application.ExitThread' to quit the
'application.

Is there a way I can prompt for confirmation before allowing the console app
to exit? And abort the termination if necessary?
 
Do you want to prompt the user with a question in console window & reload
what is on screen or can it scroll?

Would something like: 'Press Q to quit or any other key to continue' do as a
prompt?
 
Yes, any kind of prompt would do, whether it's a console prompt or a
messagebox. I need to be able to stop the console program from terminating
if the closebox is clicked.
 
Crouchie1998 said:
If you want to disable the Control Box ('X' button) then here is a
Microsoft
KB article that shows you how:

http://support.microsoft.com/default.aspx?scid=kb;en-us;818361

Thanks, I didn't know this article yet :-).

Notice that this solution is unstable. When starting the application from
within an already existing console window the close button will remain
disabled after the application has quit. When testing the application with
an explorer window for "ConsoleApplication2" opened, the explorer window's
close button was disabled, but not the button of the console window. So, to
make the code work in all these cases, some additional code would be
necessary.
 
Mr MVP,

I take it that you wrote all this in the comments box at the base of the
above KB article to notify Microsoft of their mistake choosing the
information is wrong option

Me personally, have never tried that KB article, but came across it many
months ago when searching for something else, but that just proves that the
KB search engine doesn't work correctly too
 
Crouchie,

Crouchie1998 said:
I take it that you wrote all this in the comments box at the base of the
above KB article to notify Microsoft of their mistake choosing the
information is wrong option

Yes, I posted the comments there...
 

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

Back
Top