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. C#
  4. Problem with quitting an application

Problem with quitting an application

Scheduled Pinned Locked Moved C#
questiondatabasehelpworkspace
6 Posts 2 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.
  • F Offline
    F Offline
    Frank Alviani
    wrote on last edited by
    #1

    Hi, I have an application used to print certain product info sheets. It is normally launched as a conventional application and works exactly as intended. The associated database editor can also launch it (using Process.Start()) to print any changed product sheets; in that case the application prints correctly but remains open after completing its work. If I call this.Close() explicitly from anyplace other than the Quit menu item handler an exception is thrown; using Application.Exit() or Environment.Exit() has no effect. Looking at the Process documentation on MSDN yields no obvious clues. How can I have the application quit automatically after being launched by the database editor? Thanks in advance, -Frank Alviani

    D 1 Reply Last reply
    0
    • F Frank Alviani

      Hi, I have an application used to print certain product info sheets. It is normally launched as a conventional application and works exactly as intended. The associated database editor can also launch it (using Process.Start()) to print any changed product sheets; in that case the application prints correctly but remains open after completing its work. If I call this.Close() explicitly from anyplace other than the Quit menu item handler an exception is thrown; using Application.Exit() or Environment.Exit() has no effect. Looking at the Process documentation on MSDN yields no obvious clues. How can I have the application quit automatically after being launched by the database editor? Thanks in advance, -Frank Alviani

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

      You really have no control over that. The application that you launch has to supply that kind of functionality, maybe through a command line switch. You'll have to consult with the documentation or the manufacturer of the app you're launching.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008
      But no longer in 2009...

      F 1 Reply Last reply
      0
      • D Dave Kreskowiak

        You really have no control over that. The application that you launch has to supply that kind of functionality, maybe through a command line switch. You'll have to consult with the documentation or the manufacturer of the app you're launching.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008
        But no longer in 2009...

        F Offline
        F Offline
        Frank Alviani
        wrote on last edited by
        #3

        Thanks for the info. I wrote the app myself, and know *when* I should be quitting automatically - I just can't figure out which method to call to do so :(

        D 1 Reply Last reply
        0
        • F Frank Alviani

          Thanks for the info. I wrote the app myself, and know *when* I should be quitting automatically - I just can't figure out which method to call to do so :(

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

          OK, I read the original post wrong. Application.Exit() is what you should be using. If it's not working, then you've got something else wrong in your app that is preventing your app from closing. How do you have your app processing command line arguments and printing your document? Are you doing this in the forms Load event? IIRC, calling Application.Exit() in the Load event doesn't do anything.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008
          But no longer in 2009...

          F 1 Reply Last reply
          0
          • D Dave Kreskowiak

            OK, I read the original post wrong. Application.Exit() is what you should be using. If it's not working, then you've got something else wrong in your app that is preventing your app from closing. How do you have your app processing command line arguments and printing your document? Are you doing this in the forms Load event? IIRC, calling Application.Exit() in the Load event doesn't do anything.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008
            But no longer in 2009...

            F Offline
            F Offline
            Frank Alviani
            wrote on last edited by
            #5

            Thanks for your hint. During the form constructor, I detect if I have a command line argument listing the sheets to print and immediately proceed to handle it. This occurs before the main window is shown. I now set a flag that is tested during the form_Shown() handler and if I have printed sheets I call Application.Exit() as you recommended. Works like a charm :) Again, thanks! -Frank

            D 1 Reply Last reply
            0
            • F Frank Alviani

              Thanks for your hint. During the form constructor, I detect if I have a command line argument listing the sheets to print and immediately proceed to handle it. This occurs before the main window is shown. I now set a flag that is tested during the form_Shown() handler and if I have printed sheets I call Application.Exit() as you recommended. Works like a charm :) Again, thanks! -Frank

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

              OK - it's kind of the wacky way to go about it, but whatever works. I'd normally create my own Main method, do whatever command line stuff I need to there and if I need to start the Windows Form app, branch off to the Application.Run(new MyMainForm). Other than that, let the Main method die normally.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008
              But no longer in 2009...

              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