PC Review


Reply
Thread Tools Rate Thread

Application.Idle, remove event handler?

 
 
Chien Lau
Guest
Posts: n/a
 
      10th Aug 2004
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...


 
Reply With Quote
 
 
 
 
Etienne Boucher
Guest
Posts: n/a
 
      10th Aug 2004
I can't anwser the other questions, but I would do this during the closing
of the Window if it was possible.

Etienne Boucher


 
Reply With Quote
 
Chien Lau
Guest
Posts: n/a
 
      10th Aug 2004
I had the same thought. Moving the deregistration to OnClosing() or
prior to the Close() call yields the same bad result, however.

"Etienne Boucher" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I can't anwser the other questions, but I would do this during the closing
> of the Window if it was possible.
>
> Etienne Boucher
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to remove event handler moondaddy Microsoft Dot NET 10 28th Jul 2010 07:05 AM
adding a event handler in MFC application for c# event Mayur Gadhave Microsoft VC .NET 2 30th Aug 2006 08:14 AM
adding a event handler in MFC application for c# event Mayur Gadhave Microsoft C# .NET 0 30th Aug 2006 07:38 AM
Application.Idle, remove event handler? Chien Lau Microsoft C# .NET 2 10th Aug 2004 04:35 AM
How to Remove an Event Handler without knowing the name of the handler Charles Law Microsoft VB .NET 4 10th Jun 2004 03:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:35 PM.