|
-
Nov 12th, 2009, 10:31 AM
#1
Thread Starter
Addicted Member
[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
-
Nov 12th, 2009, 11:12 AM
#2
Addicted Member
Re: application does not stop on close
 Originally Posted by DebbieInFlorida
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).
-
Nov 12th, 2009, 11:13 AM
#3
Fanatic Member
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).
-
Nov 12th, 2009, 11:17 AM
#4
Re: application does not stop on close
Or, you could just call End.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Nov 12th, 2009, 04:18 PM
#5
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:
 Originally Posted by weirddemon
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.
-
Nov 12th, 2009, 04:47 PM
#6
Re: application does not stop on close
 Originally Posted by _powerade_
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
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Nov 12th, 2009, 04:47 PM
#7
Fanatic Member
Re: application does not stop on close
Unless its an MDI form you can not replace the Me.Close with App exit.
-
Nov 12th, 2009, 04:48 PM
#8
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.
-
Nov 12th, 2009, 04:59 PM
#9
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
-
Nov 12th, 2009, 05:11 PM
#10
Re: application does not stop on close
 Originally Posted by Negative0
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
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Nov 12th, 2009, 06:53 PM
#11
Re: application does not stop on close
 Originally Posted by Negative0
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
-
Nov 13th, 2009, 09:42 AM
#12
Fanatic Member
Re: application does not stop on close
Yes, I would think so.
 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
-
Nov 13th, 2009, 09:53 AM
#13
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.
-
Nov 13th, 2009, 10:34 AM
#14
Addicted Member
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.
-
Nov 13th, 2009, 11:23 AM
#15
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
-
Nov 16th, 2009, 09:03 AM
#16
Thread Starter
Addicted Member
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
-
Nov 17th, 2009, 07:10 PM
#17
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
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Nov 18th, 2009, 07:57 AM
#18
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|