Results 1 to 11 of 11

Thread: Preferred way to exit an application?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Preferred way to exit an application?

    What is the preferred method to shut down an application? I've always used "End" in the Form_Closing Event. I know this isn't a big deal but still want to stay with the current accepted standard.

    Thanks,
    Blake

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Preferred way to exit an application?

    close all forms, stop all processes, dispose of any remaining objects, and quietly exit. Make sure that your Application Settings are set correctly (there is an option where you can control if the app ends on the closing of the main form, or when the last remaining form is closed... select according to your needs).

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Preferred way to exit an application?

    tech,

    That doesn't sound like a quiet exit. I know how to close all forms, not sure how to stop "All" processes, not sure how to tell what remaining objects need disposed. Applications Settings I know nothing about. Never used it before. Do you have any code examples or screenshots or links?
    Blake

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Preferred way to exit an application?


  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Preferred way to exit an application?

    That's what I was looking for Paul...thanks!

    I'm guessing that statement goes in the Form_Closing() Event?
    Blake

  6. #6
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Preferred way to exit an application?

    Quote Originally Posted by blakemckenna View Post
    What is the preferred method to shut down an application? I've always used "End" in the Form_Closing Event. I know this isn't a big deal but still want to stay with the current accepted standard.

    Thanks,
    It's not a big deal? Using END is a big deal and it is not shutting down any thing. It is simply crashing your application.

    Classic VB - Why is using the 'End' statement (or VB's "stop" button) a bad idea

  7. #7
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,373

    Re: Preferred way to exit an application?

    My application enters in the MyApplication_Startup event in which I call a login screen. If authentication is successful then the application opens its "Startup form". If authentication is not successful then I want to exit the application before the startup form is shown.

    In the event of an unsuccessful login:

    Firstly, I can't call Application.Exit directly from this event. I can only call it from a sub in another module.

    Secondly, if I don't follow it with the End command, the startup form opens.

    How can I close the application from this event without using the End command?

  8. #8
    Hyperactive Member
    Join Date
    Nov 2008
    Location
    PA
    Posts
    365

    Re: Preferred way to exit an application?

    If authentication is not successful then I want to exit the application before the startup form is shown.
    Might I suggest looking at JMC's codebank submissions. He has a great on on logon forms. Helped me in the past.

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Preferred way to exit an application?

    Quote Originally Posted by robertx View Post
    My application enters in the MyApplication_Startup event in which I call a login screen. If authentication is successful then the application opens its "Startup form". If authentication is not successful then I want to exit the application before the startup form is shown.

    In the event of an unsuccessful login:

    Firstly, I can't call Application.Exit directly from this event. I can only call it from a sub in another module.

    Secondly, if I don't follow it with the End command, the startup form opens.

    How can I close the application from this event without using the End command?
    Did you actually bother to read the documentation for that event? Why do I even ask? If you had then you would have seen this:
    Quote Originally Posted by MSDN
    You can use the Cancel property of the e parameter to control the loading of an application's startup form. When the Cancel property is set to True, the startup form does not start.
    That's 30 seconds work to find that and reading the documentation should have been the first thing you did.
    Quote Originally Posted by detlion1643 View Post
    Might I suggest looking at JMC's codebank submissions. He has a great on on logon forms. Helped me in the past.
    You can follow the CodeBank link in my signature below and check out my WinForms Login thread, which demonstrates cancelling the Startup event.

  10. #10
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,373

    Re: Preferred way to exit an application?

    Quote Originally Posted by detlion1643 View Post
    Might I suggest looking at JMC's codebank submissions. He has a great on on logon forms. Helped me in the past.
    Quote Originally Posted by jmcilhinney View Post
    You can follow the CodeBank link in my signature below and check out my WinForms Login thread, which demonstrates cancelling the Startup event.
    Thanks. Yes the codebank submission was very helpful.

    e.Cancel closes the app without the need for End or Application.Exit and also does so more quickly and efficiently.

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Preferred way to exit an application?

    Quote Originally Posted by robertx View Post
    Thanks. Yes the codebank submission was very helpful.

    e.Cancel closes the app without the need for End or Application.Exit and also does so more quickly and efficiently.
    That Startup event would be raised from the Main method and then the creation of the startup form and the call to Application.Run would be inside an If statement that checks whether e.Cancel is False. It's quicker and more efficient because it stops things being built in the first place rather than tearing them down afterwards.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width