Console Application Problems
-
Im using a console application because the program im working on is for automation purposes. Only problem is, i can figure out how to end the program. In a forms based program is is ME/MYBASE/THIS(C#).Close (because the program is a class) in the console its none of these. Ive tried Wrapping the API call of FreeConsole from Kernel.lib and it works only it doesnt stop the undrlying process just the window. Is there an easy way to do that that i may be overlooking? Thanks Very much for the help. G. R. Martin
-
Im using a console application because the program im working on is for automation purposes. Only problem is, i can figure out how to end the program. In a forms based program is is ME/MYBASE/THIS(C#).Close (because the program is a class) in the console its none of these. Ive tried Wrapping the API call of FreeConsole from Kernel.lib and it works only it doesnt stop the undrlying process just the window. Is there an easy way to do that that i may be overlooking? Thanks Very much for the help. G. R. Martin
If your application is single-threaded then when the Main method completes the console application quits.
Do you want to know more? Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
-
If your application is single-threaded then when the Main method completes the console application quits.
Do you want to know more? Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
-
yeah i know but i need to to prematurely quit... say on error... and im 4 functions down... and it cant just send me to an error dialog... has to print to a screen ... wait for any keypress and then terminate like a good dos program does...
I dont' know if this will work for you (I don't get into console apps very much), but you could try
Application.Exit()
. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome -
yeah i know but i need to to prematurely quit... say on error... and im 4 functions down... and it cant just send me to an error dialog... has to print to a screen ... wait for any keypress and then terminate like a good dos program does...
Then throw an exception. Create an exception class that is used for nothing else than premature exit. When you need to exit early throw the exception. Wrap everything in your main in a try/catch block and catch this specific exception. The catch handler can then process the exit in a considerate manner.
Do you want to know more? Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
-
I dont' know if this will work for you (I don't get into console apps very much), but you could try
Application.Exit()
. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming GnomeNo it doesnt... if this were C# Forms or VB forms that might work, however... a console app is a module, it hasnt got a class name or functions behind it beside what it builds... id need to say get a handle of the running thread, and tell that thread to terminate... im just not sure as to how i should do that. Ive wrapped a few of the console APIs... FreeConsole onle destroys the window handle to the console itself... it doesnt terminate the process behind it...
-
No it doesnt... if this were C# Forms or VB forms that might work, however... a console app is a module, it hasnt got a class name or functions behind it beside what it builds... id need to say get a handle of the running thread, and tell that thread to terminate... im just not sure as to how i should do that. Ive wrapped a few of the console APIs... FreeConsole onle destroys the window handle to the console itself... it doesnt terminate the process behind it...
Oh well, it was just a quick thought... In that case, I'd implement a scheme as Colin suggests. Be sure it is a custom defined Exception and throw that when you need to. Make sure that the only Exception Handler that can handle that exception is the one in Main. All other exception handlers must not handle this exception if they do, must catch, then re-throw the exception to send it up the call chain back to Main. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Im using a console application because the program im working on is for automation purposes. Only problem is, i can figure out how to end the program. In a forms based program is is ME/MYBASE/THIS(C#).Close (because the program is a class) in the console its none of these. Ive tried Wrapping the API call of FreeConsole from Kernel.lib and it works only it doesnt stop the undrlying process just the window. Is there an easy way to do that that i may be overlooking? Thanks Very much for the help. G. R. Martin
Is this what you are looking for?
System.Environment.Exit(0)
Jason -
Is this what you are looking for?
System.Environment.Exit(0)
Jason