Pogram does not terminate but stays as a process!!!
Hello,
I have this strange problem.
Sometimes (I cannot figure out exactly curcimstances), my application does not unload from Windows, looses GUI and remains running as a process.
What can cause that?
My unloading routine contains this:
Dim F As Form
For Each F In Forms
Unload F
Next
as the last lines of code.
That was fine working for the last 10 years, but now I have started having that problem.
Your thoughts appreciated,
jas
Re: Pogram does not terminate but stays as a process!!!
Do you have it in the form_unload event?
Re: Pogram does not terminate but stays as a process!!!
Code:
Dim F As Form
For Each F In Forms
If F.Name <> Me.Name Then Unload F
Next
Unload Me
May help.
Re: Pogram does not terminate but stays as a process!!!
Or just use proper owner relationships (the Owner argument of the Show method).
These kinds of "sweep all Forms" loops smack of general disorganization in a program. There may even be other orphaned objects keeping the program running. This is usually caused by circular references.
You might read the manual, in particular Visual Basic Component Shutdown Rules, Starting and Ending a Component, Dealing with Circular References, and similar topics.
But usually you're using the default instances of Forms (the ones with the same name as the Form class that you get "for free"). These have "As New" semantics, and touching the variable after unloading it causes a new instance to be reloaded. That's what Magic Ink is probably getting at above.
Re: Pogram does not terminate but stays as a process!!!
Magic Ink's code should work to unload all of your app's forms (make sure you put it in your app's main form). Then if your application still does not close, you might have other code running from other "formless" areas of your application eg a formless timer, or you have set references to objects that are persisting in memory and which must be removed for your application to close, in which case check for any global objects and make sure they are also closed properly prior to exiting your application.