Ending a program while in Form_Load

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dom

    Ending a program while in Form_Load

    How do I end a program while in Form_Load? I tried both this.Close(),
    and Application.Exi t(), but neither will just end the program there
    and then. Instead, both allow Form_Load to continue.
  • Peter Duniho

    #2
    Re: Ending a program while in Form_Load

    On Tue, 25 Mar 2008 14:09:52 -0700, Dom <dolivastro@gma il.comwrote:
    How do I end a program while in Form_Load? I tried both this.Close(),
    and Application.Exi t(), but neither will just end the program there
    and then. Instead, both allow Form_Load to continue.
    Well, I suppose you could just throw an exception, or just put a "return"
    statement after your call to Application.Exi t(). That would prevent the
    rest of your Load event handler from executing.

    The Application.Exi t() method isn't like the old CRT "exit()" function.
    It doesn't terminate the process. It just signals to the application
    message pumps to stop and closes all the windows.

    I'm not aware of a .NET equivalent to "exit()", though of course an
    unhandled exception can terminate the application, albeit messily. You
    should avoid implementing code that just terminates the process. It's
    extremely unlikely that there's a good reason for wanting to do this, and
    you're better off exiting your application cleanly.

    Pete

    Comment

    • Peter Duniho

      #3
      Re: Ending a program while in Form_Load

      On Tue, 25 Mar 2008 14:59:37 -0700, Jon Skeet [C# MVP] <skeet@pobox.co m>
      wrote:
      >I'm not aware of a .NET equivalent to "exit()" [...]
      >
      Environment.Exi t() is *reasonably* close to exit() I believe.
      Perhaps. The docs are extremely vague on exactly how it operates, but
      yes...it appears reasonably close to exit().

      Still, I wouldn't recommend it as a correct way of exiting a .NET Forms
      application. :)

      Pete

      Comment

      • Peter Duniho

        #4
        Re: Ending a program while in Form_Load

        On Wed, 26 Mar 2008 14:17:57 -0700, Ignacio Machin ( .NET/ C# MVP )
        <ignacio.machin @gmail.comwrote :
        I agree with you. But maybe his main form is just a splash form, if so
        it would make sense to display it
        I'm not sure what you mean. The OP has made it very clear that he wants
        to optionally continue with the program based on the user's response to a
        _dialog_. I don't think there's any "maybe" about this hypothetical
        splash form of which you speak.

        On the other hand, if one is talking more generally about how to display a
        splash form, sure...that's possible and wouldn't involve any conditional
        stuff based on the display of that form. But I'm not sure how that'd be
        relevant in this thread.

        Pete

        Comment

        • Dom

          #5
          Re: Ending a program while in Form_Load

          On Mar 26, 6:41 pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
          wrote:
          On Wed, 26 Mar 2008 14:17:57 -0700, Ignacio Machin ( .NET/ C# MVP )  
          >
          <ignacio.mac... @gmail.comwrote :
          I agree with you. But maybe his main form is just a splash form, if so
          it would make sense to display it
          >
          I'm not sure what you mean.  The OP has made it very clear that he wants 
          to optionally continue with the program based on the user's response to a  
          _dialog_.  I don't think there's any "maybe" about this hypothetical  
          splash form of which you speak.
          >
          On the other hand, if one is talking more generally about how to display a 
          splash form, sure...that's possible and wouldn't involve any conditional  
          stuff based on the display of that form.  But I'm not sure how that'd be 
          relevant in this thread.
          >
          Pete
          Pete got it right. I don't want the main form shown at all if the
          user cancels from the dialog that comes before it. The dialog gives
          the user the options that are available at the moment, none of which
          may be appropriate.

          Pete's solution worked fine for me.

          Dom

          Comment

          Working...