I have some Objects that Expire after a certain amount of time. Right now I am using a Single timer to raise an event every 10 seconds and run thru the object collection and see if anything has expired.
Instead of this I am considering adding a timer to each object and setting it to fire an event to expire at the desired time.
I think the most appropriate timer is the System.Timers.Timer
Does any one have any thoughts on this?
I have a test rig so I will be able to compare what I have now and the refactored implementation but I would like to think this is a good idea before I start.
I do prefer
System.Threading.Timerover the one you mentioned. The reason is thatSystem.Timers.Timerwill consume all unhandled exceptions and therefore hide errors in your application.I would also make a list of objects and traverse it in the timer method. It’s a sound approach and not very hard to implement (Keep It Simple and Stupid)
The only reason to not do so is if it’s important that the objects are check after exactly 10 seconds (and not 11 or 12 seconds). It all depends on how long each execution takes.