473,395 Members | 1,999 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 3696
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chien Lau | last post by:
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: ...
1
by: Weber Samuel | last post by:
Hi NG i try to catch the Application.Idle Event: --> Application.Idle += new EventHandler(OnIdle); Here's my problem: If i put a Label on my Form and set the Property AutoSize = true then...
19
by: Frank Rizzo | last post by:
I want to log the user out when there has been a period of inactivity in the application. The key here is inactivity of the application, not the system. I know that you can retrieve the...
5
by: Frank Rizzo | last post by:
Hello, I have a dozen 3rd party controls on my form. I am trying to detect when the application is idle. But even after the mouse and the keyboard are no longer moving, something is still...
5
by: Leon | last post by:
Is there a way I can create a thread at application level that running all the time along with application exists? I have tried to do the above thing, and I found for some reason, the thread only...
20
by: J-T | last post by:
We are working on an asp.net application which is a 3-tier application.I was aksed to create a component which monitors a folder and gets the file and pass them to a class library in our business...
2
by: sbcglobal | last post by:
Anyone knows how to add an Application.Idle handler in VB .Net Private WithEvents ?????????? As ???????? Public Sub IdleEvent(ByVal sender As System.Object, ByVal e As System.EventArgs)...
2
by: Lucas Tam | last post by:
Without writing try/catch statements is there a way to have a global error handler in VB.NET? In ASP.NET there is an application level error handler inside Global.asax, but is there something...
1
by: Rob | last post by:
How can I write the following code in VB.NET : private void Form1_Load(object sender, System.EventArgs e) { // Submit to Idle event to set controls state at idle time Application.Idle += new...
4
by: Udi | last post by:
Hi All, What do you know about the Application.Idle event? When is it a good practice to use it and when should I not use it? I know it fires when the app message queue is empty, and that this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.