Tip : VB.NET Form Won't Close on Me.Close + User Controls 
Author Message
 Tip : VB.NET Form Won't Close on Me.Close + User Controls

I was having some problems closing my winform on me.close() after filling
the page with my own user controls. After some searching I came across
newsgroup articles explaining it was a known bug with Microsoft that forms
don't close in some cases where usercontrols have focus.  It turned out to
be a bug in my programming not Microsoft !

On closing the form, I remove all controls from page leaving a blank screen
with 0 controls and then I fire a GC.Collect [ multiple instances of forms
can become a memory hog so I force the clearing of memory on exit of the
form ] then finally I call me.close.  The page would remove all the controls
as it should however, the page remained blank and could not be closed.

The Cause :
------------
You haven't disposed of all the objects and controls on the form

The Solution :
--------------
make sure that you dispose of all your controls, and objects.  Even one
unclosed object will cause this form to hang and not close.  After disposing
of all my objects properly the form closed without any problems, and the
memory released immediately [ via GC.Collect ].

AmiT ChandeL



Thu, 08 Sep 2005 06:18:28 GMT  
 Tip : VB.NET Form Won't Close on Me.Close + User Controls
Why do you remove all your controls by yourself? The form will handle the
disposal of the controls and the occupied memory itself if you close it,
there is no need to do it yourself (and it can even do more harm, as you
have experienced yourself). And there is no need to call GC.Collect either,
the .NET framework will handle this for you.

Best regards
Urs



Quote:
> I was having some problems closing my winform on me.close() after filling
> the page with my own user controls. After some searching I came across
> newsgroup articles explaining it was a known bug with Microsoft that forms
> don't close in some cases where usercontrols have focus.  It turned out to
> be a bug in my programming not Microsoft !

> On closing the form, I remove all controls from page leaving a blank
screen
> with 0 controls and then I fire a GC.Collect [ multiple instances of forms
> can become a memory hog so I force the clearing of memory on exit of the
> form ] then finally I call me.close.  The page would remove all the
controls
> as it should however, the page remained blank and could not be closed.

> The Cause :
> ------------
> You haven't disposed of all the objects and controls on the form

> The Solution :
> --------------
> make sure that you dispose of all your controls, and objects.  Even one
> unclosed object will cause this form to hang and not close.  After
disposing
> of all my objects properly the form closed without any problems, and the
> memory released immediately [ via GC.Collect ].

> AmiT ChandeL



Fri, 09 Sep 2005 20:15:43 GMT  
 Tip : VB.NET Form Won't Close on Me.Close + User Controls
Calling GC.Collect releases it from memory at that instant (req'd for my app
due to multiple instances of forms which take about 10MB each, mostly GDI).
If I don't call it, the garbage collector will hold it in memory, maxing it
out, only to release it upto 20 minutes later all at once or when your CPU
is idle.  This 'batch' clearing of memory spikes the CPU as well.  To avoid
all this, i call GC.Collect on form close.

I clear my controls from my form in the same way objects are disposed.  Each
control has a real-time connection streaming data from a websvc, so it's
more of a precautionary measure than anything else.


Quote:
> Why do you remove all your controls by yourself? The form will handle the
> disposal of the controls and the occupied memory itself if you close it,
> there is no need to do it yourself (and it can even do more harm, as you
> have experienced yourself). And there is no need to call GC.Collect
either,
> the .NET framework will handle this for you.

> Best regards
> Urs



> > I was having some problems closing my winform on me.close() after
filling
> > the page with my own user controls. After some searching I came across
> > newsgroup articles explaining it was a known bug with Microsoft that
forms
> > don't close in some cases where usercontrols have focus.  It turned out
to
> > be a bug in my programming not Microsoft !

> > On closing the form, I remove all controls from page leaving a blank
> screen
> > with 0 controls and then I fire a GC.Collect [ multiple instances of
forms
> > can become a memory hog so I force the clearing of memory on exit of the
> > form ] then finally I call me.close.  The page would remove all the
> controls
> > as it should however, the page remained blank and could not be closed.

> > The Cause :
> > ------------
> > You haven't disposed of all the objects and controls on the form

> > The Solution :
> > --------------
> > make sure that you dispose of all your controls, and objects.  Even one
> > unclosed object will cause this form to hang and not close.  After
> disposing
> > of all my objects properly the form closed without any problems, and the
> > memory released immediately [ via GC.Collect ].

> > AmiT ChandeL



Sat, 17 Sep 2005 07:04:01 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How to prevent user closing a mdi form using the close control button

2. Preventing a VB app from closing when user logs off in Win '95

3. Prevent user from closing form using caption close button

4. Trying to close a VB form from inside a user control object

5. Access form won't close using VBA

6. Form Won't close

7. Form that won't close

8. Close from Control Box Doesn't Close Application

9. Closing Form when WebBrowser control close

10. Ctrl-F4 won't close child windows in VB5 with some controls

11. MS Comm Control won't close port

12. Access 97 Won't Close after EXCEL VB Modules

 

 
Powered by phpBB® Forum Software