Results 1 to 18 of 18

Thread: [RESOLVED] application does not stop on close

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Posts
    193

    Resolved [RESOLVED] application does not stop on close

    vb.net application, when the user closes the last form (the code is me.close) the application looks to stop, but it is still running in taskmanager??????

    what else can I do???
    thanks

  2. #2
    Addicted Member
    Join Date
    Nov 2008
    Location
    UK
    Posts
    171

    Re: application does not stop on close

    Quote Originally Posted by DebbieInFlorida View Post
    vb.net application, when the user closes the last form (the code is me.close) the application looks to stop, but it is still running in taskmanager??????

    what else can I do???
    thanks
    Have you made sure no other forms are open?

    When the form close, loop through other forms and close them down or just use form2.close etc (they could be hidden).

  3. #3
    Fanatic Member
    Join Date
    Jun 2004
    Location
    All useless places
    Posts
    917

    Re: application does not stop on close

    You might want to add an application exit event handler to do a clean exit when all forms are closed (http://msdn.microsoft.com/en-us/libr...ationexit.aspx).

  4. #4
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: application does not stop on close

    Or, you could just call End.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  5. #5
    Fanatic Member Arve K.'s Avatar
    Join Date
    Sep 2008
    Location
    Kyrksæterøra, Norway
    Posts
    518

    Re: application does not stop on close

    This has happened a few times with me also. The reason is that I had a backgroundworker doing some work, so the application remained in the task manager until the backgroundworker was done.

    Btw, isn't it better to use Application.Exit instead of Me.Close???

    Edit:
    Quote Originally Posted by weirddemon View Post
    Or, you could just call End.
    Didn't know we could do this

    Ok, so we have at least three ways to close a program... But which one is the most preffered one??
    Last edited by Arve K.; Nov 12th, 2009 at 04:25 PM.
    Arve K.

    Please mark your thread as resolved and add reputation to those who helped you solve your problem
    Disclaimer: I am not a professional programmer

  6. #6
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: application does not stop on close

    Quote Originally Posted by _powerade_ View Post
    This has happened a few times with me also. The reason is that I had a backgroundworker doing some work, so the application remained in the task manager until the backgroundworker was done.

    Btw, isn't it better to use Application.Exit instead of Me.Close???

    Edit:


    Didn't know we could do this

    Ok, so we have at least three ways to close a program... But which one is the most preffered one??
    Me.Close will only the close the form it is called on. If that happens to be the last form and the app is set to close on the last form, then the apps closes.

    If I'm not mistaken, Application.Close and End probably do the same thing.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  7. #7
    Fanatic Member
    Join Date
    Jun 2004
    Location
    All useless places
    Posts
    917

    Re: application does not stop on close

    Unless its an MDI form you can not replace the Me.Close with App exit.

  8. #8
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: application does not stop on close

    If you read the MSDN documentation on Application.Exit and End, you will find that you should using them very sparingly as they bypass code that would normally be executed if you closed using me.close(). In the case of Application.Exit, your form.closed and form.closing events never get fired. In the case of End, it will stop immediately and not dispose of any objects or even go through a finally block if you are in a try..catch..finally block.

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: application does not stop on close

    Check your project properties. There's a setting that can be changed to indicate when the app closes. Some options are When Main Form Closes, When Last Form Closes... there may be more.... might want to take a look at that. Might also be a good idea to see what operations you are doing that might be keeping the app alive. Could be that there's something you aren't closing or disposing properly that keeps the app going.

    -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??? *

  10. #10
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: application does not stop on close

    Quote Originally Posted by Negative0 View Post
    If you read the MSDN documentation on Application.Exit and End, you will find that you should using them very sparingly as they bypass code that would normally be executed if you closed using me.close(). In the case of Application.Exit, your form.closed and form.closing events never get fired. In the case of End, it will stop immediately and not dispose of any objects or even go through a finally block if you are in a try..catch..finally block.
    Ah. Sounds good. That's pretty useful information
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  11. #11
    Fanatic Member Arve K.'s Avatar
    Join Date
    Sep 2008
    Location
    Kyrksæterøra, Norway
    Posts
    518

    Re: application does not stop on close

    Quote Originally Posted by Negative0 View Post
    In the case of Application.Exit, your form.closed and form.closing events never get fired.
    You mean they get fired??
    Last edited by Arve K.; Nov 13th, 2009 at 02:05 PM. Reason: typo (i think???) :p
    Arve K.

    Please mark your thread as resolved and add reputation to those who helped you solve your problem
    Disclaimer: I am not a professional programmer

  12. #12
    Fanatic Member
    Join Date
    Jun 2004
    Location
    All useless places
    Posts
    917

    Re: application does not stop on close

    Yes, I would think so.
    Quote Originally Posted by MSDN
    The Exit method stops all running message loops on all threads and closes all windows of the application. This method does not necessarily force the application to exit. The Exit method is typically called from within a message loop, and forces Run to return. To exit a message loop for the current thread only, call ExitThread.

    Exit raises the following events and performs the associated conditional actions:

    A FormClosing event is raised for every form represented by the OpenForms property. This event can be canceled by setting the Cancel property of their FormClosingEventArgs parameter to true.

    If one of more of the handlers cancels the event, then Exit returns without further action. Otherwise, a FormClosed event is raised for every open form, then all running message loops and forms are closed.
    Source: http://msdn.microsoft.com/en-us/library/ms157894.aspx

  13. #13
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: application does not stop on close

    Actually after re-checking MSDN, i found I was on the .net 1.1 page and not the 3.5 page, so what you are stating is correct.

  14. #14
    Addicted Member
    Join Date
    Oct 2008
    Posts
    152

    Re: application does not stop on close

    Application.Exit seems to be a work-a-round to force a close but as stated above your not looking at what might be causing the problem in the first place such as something possibly still being processed in the background. I would suggest determining what exactly is still running at the time before deciding whether or not it would cause problems to force the action to cease before finishing. For instance if perhaps it is data being written to a file or saved to the database, you dont want to end it prematurely and lose data.

    You mentioned that the program continues to run in Task Manager, I'm curious to know how its effecting Visual Studio itself? For example, if you run the app from Visual Studio and close out your forms is the app still in run mode in the design environment? If so you can click on ctrl + break keys and possibly see what is running at the time.

  15. #15
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: application does not stop on close

    Above all else... avoid using End.... it's like turning off the engine to your car while still running at 60mph. Using Application.Exit is safer, more like throwing it into neutral and letting the car coast before shutting down the engine. But as I pointed out, and Tom reiterated, there's still some part of your application that is running. You should take the time to track it down and make sure that you are closing all of your processes.

    look for timers, background worker threads, and forms that you've hidden (but never closed). Make sure you've used the .Dispose method on your objects where applicable.

    -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??? *

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Posts
    193

    Re: application does not stop on close

    WOW, thanks for all the replies. All good ideas. I have checked for any forms open, and there are none, I stepped thru each one closing, the app does all the .dispose as well and application shutdown. Even in design mode I stop the application, it is still running in task manager??? is there any way to force it out of task manager?

    thanks

  17. #17
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: application does not stop on close

    If it's not the form, then it's likely another thread. Do you have any open threads?
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Posts
    193

    Thumbs up Re: application does not stop on close

    OK, I goofed, there was one small form (out of 20!) that I missed it was hidden and wasn't closed at the end. Sorry, my bad. THanks for all the great feedback..

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