System.Threading.Timer - How to know when to dispose timer reference?

B

Bruce

Hi
I have a question on using System.Threading.Timer. I understand that
in order for the timer to work, I need to store a reference to the
timer so that it does not get garbage collected.
In my application, I create a lot of timers - so I have a StoreTimer
class that has a method AddTimer that other classes can call. Inside
AddTimer, I create timers and store references to them inside a class
level hashtable.

My problem is when to remove these from the hashtable. There is no
onFired event on the timer object
,and my timer callback methods are outside the scope of my StoreTimer
class.
And I don't want to rely on the users of my StoreTimer class to call a
remove timer method so that I can remove them from the hashtable.

Does anyone has any suggestions? I could create another timer that
will fire at the same time so that I can remove the original timer
from the hashtable, but that seems lame to me.

Thanks!
Bruce
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top