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
Printable View
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
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).
Or, you could just call End.
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??
Unless its an MDI form you can not replace the Me.Close with App exit.
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.
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
Yes, I would think so.Source: http://msdn.microsoft.com/en-us/library/ms157894.aspxQuote:
Originally Posted by MSDN
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.
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.
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
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
If it's not the form, then it's likely another thread. Do you have any open threads?
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..