469,579 Members | 1,899 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Application.Idle, remove event handler?

I have a form class that acts as a top level window. The user can open
and close any number of these windows throughout the lifetime of the
application. In the OnLoad, I have:

Application.Idle+=new EventHandler(Application_Idle);

....and in the Dispose() override, I have:

Application.Idle-=new EventHandler(Application_Idle);

First question: Is the call in Dispose() necessary? I suspect it is. If
it weren't called, the Application object would continue to reference a
pointer to a disposed form. This wouldn't matter if the application were
about to shut down, but in a situation where the user continually opened and
closed these windows throughout the day/week, a memory leak would occur. Is
this correct?

I'm asking this because of a bug that's been in the WinForms framework
for sometime now. It occurs when an application closes. It only occurs in
debug mode. The symptom is as follows: The garbage collector thread crashes
with an unhandled exception (NullReferenceException). It turns out that
removing the idle event deregistration code in Dispose() fixes the error...
but it got me to wondering: Is it really necessary to perform this
deregistration at all?

Thanks...
Nov 22 '05 #1
2 3304
I can't anwser the other questions, but I would do this during the closing
of the Window if it was possible.

Etienne Boucher
Nov 22 '05 #2
I had the same thought. Moving the deregistration to OnClosing() or
prior to the Close() call yields the same bad result, however.

"Etienne Boucher" <et*****@novat.qc.ca> wrote in message
news:OL**************@TK2MSFTNGP10.phx.gbl...
I can't anwser the other questions, but I would do this during the closing
of the Window if it was possible.

Etienne Boucher

Nov 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Chien Lau | last post: by
1 post views Thread by Weber Samuel | last post: by
19 posts views Thread by Frank Rizzo | last post: by
5 posts views Thread by Frank Rizzo | last post: by
5 posts views Thread by Leon | last post: by
2 posts views Thread by sbcglobal | last post: by
2 posts views Thread by Lucas Tam | last post: by
1 post views Thread by Rob | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.