Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Console Application Problems

Console Application Problems

Scheduled Pinned Locked Moved Visual Basic
helpcsharptestingtoolsjson
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GRMartin
    wrote on last edited by
    #1

    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

    C J 2 Replies Last reply
    0
    • G GRMartin

      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

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      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!

      G 1 Reply Last reply
      0
      • C Colin Angus Mackay

        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!

        G Offline
        G Offline
        GRMartin
        wrote on last edited by
        #3

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

        D C 2 Replies Last reply
        0
        • G GRMartin

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

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          G 1 Reply Last reply
          0
          • G GRMartin

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

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #5

            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!

            1 Reply Last reply
            0
            • D Dave Kreskowiak

              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

              G Offline
              G Offline
              GRMartin
              wrote on last edited by
              #6

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

              D 1 Reply Last reply
              0
              • G GRMartin

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

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • G GRMartin

                  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

                  J Offline
                  J Offline
                  Jason Weibel
                  wrote on last edited by
                  #8

                  Is this what you are looking for? System.Environment.Exit(0) Jason

                  A 1 Reply Last reply
                  0
                  • J Jason Weibel

                    Is this what you are looking for? System.Environment.Exit(0) Jason

                    A Offline
                    A Offline
                    Anonymous
                    wrote on last edited by
                    #9

                    Yes... Thank you... sometimes i wonder if they hide things on purpose... But thank you so much :-D

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups