Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 18th, 2005, 3:21 PM   #1
MBirchmeier
Hobbyist Programmer
 
Join Date: Oct 2005
Posts: 211
Rep Power: 3 MBirchmeier is on a distinguished road
.NET Timer Form closing issue

This question pertains specifically to the .NET Compact framework version 1.1.

The problem is using Timers with the Form.ShowDialog() and Form.Close() command.

When a timer is created on a form with the Form.Show() command it is attached to the form, so that the form will stop and (supposedly) close the timer when the form is destroyed, however with the ShowDialog command is used.

However when using the ShowDialog command the timer is attached differently to the form so that it can keep running after the form has been closed, and in some cases even destroyed. (note: We can't use Show instead of ShowDialog() for various other reasons, notably our dynamic creations of forms from a database tends to issues with Form.Show())

This causes two problems.

First we'll occasionally have a timer run, that because the form underneath it has been destroyed, that will cause various unhandled null reference exceptions and the like.

Secondly : Even if the timer is not running, it appears that it is never getting destroyed, since that is normally handled in the form destruction code. (Or the code will keep running, without causing an exception) causing a small possibly undetectable memory leak. (This code is designed to run for months if not years at a time, a small memory leak can be substancial, we've ran tests of several weeks at a time without problem, but a leak this small we might not be able to detect over such a small period of time)

Is there a way to force the timers destruction with the destruction or closing of the form? Additionally is there a way to automate this process to prevent from having to individually evaluate each form.

Thanks,
-MBirchmeier
MBirchmeier is offline   Reply With Quote
Old Nov 18th, 2005, 5:35 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
In the form's Close event, call the timer's Dispose function:
Timer1.Dispose();
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Nov 21st, 2005, 8:19 AM   #3
MBirchmeier
Hobbyist Programmer
 
Join Date: Oct 2005
Posts: 211
Rep Power: 3 MBirchmeier is on a distinguished road
Quote:
Originally Posted by Ooble
In the form's Close event, call the timer's Dispose function:
Timer1.Dispose();
This actually doesn't quite work, there's situations where the close event occurs before all of the timers are fully initialized. (.NET is an odd language timingwise)

It was suggested elsewhere that the timer class be overrided and have a method that watches the form beneath it and destroys when in destroys.
The other option would be to add a Form.Closed() event and close it there.

-MBirchmeier
MBirchmeier is offline   Reply With Quote
Old Nov 21st, 2005, 9:50 AM   #4
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
You can modify the overloaded Dispose() method to explicitly destroy the timer. As you might know, the Dispose() method is called when the form is closed.
OpenLoop is offline   Reply With Quote
Old Nov 21st, 2005, 10:00 AM   #5
MBirchmeier
Hobbyist Programmer
 
Join Date: Oct 2005
Posts: 211
Rep Power: 3 MBirchmeier is on a distinguished road
Quote:
Originally Posted by OpenLoop
You can modify the overloaded Dispose() method to explicitly destroy the timer. As you might know, the Dispose() method is called when the form is closed.
This was discussed as a solution, but it's one we're trying to avoid. It would require code changes in quite a few places (2 or 3 dozen... the project design wasn't exactly thought out early on). So we're trying to make functional changes in as few places as possible.

-MBirchmeier
MBirchmeier is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:49 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC