Multiple dynamic timers

Posted by Rickard on Stack Overflow See other posts from Stack Overflow or by Rickard
Published on 2012-07-05T02:02:44Z Indexed on 2012/07/05 3:15 UTC
Read the original article Hit count: 358

Filed under:
|

I am working on a project where I need to let the user create one (or more) timers to fire off an event. The user is supposed to define variables such as if the timer should be active and how often the timer will fire along with some other variables of what will happen when the timer is fiering.

All these variables are stored in a dictionary (Disctionary) where the object holds all the variables the user has set and the string is the name that the user has chosen for this timer.

I then want my program to loop through this dictionary and search for all objects which has the variable t_Active set to true (this I have already achieved). What I need help with figuring out is the follwoing: When it detects the variable, and if it's set to true, I need the program to see if there is already a timer created for this. If it isn't, it should create one and set the relevant parameters for the timer. The two variables t_num and t_period should decide the interval of the timer. t_num is an int and t_period is a string which will be set to either minutes, hours or days.

Combining t_num with 60000 (minutes), 3600000 (hours) or 86400000 should give the corrct interval.

But how would I go on about programatically create a timer for each user-defined active object? And how do I get the program to detect wether or not a timer has already been created?

I have been searching both here and on google, but so far I haven't come across something that makes sense to me. I am still learning C#, so what make sense to you guys may not neccessarilly make sense to me yet. :)

I hope I have explaned what I need good enough, please do ask me to clarify if you don't get me.

Edit:

Maybe I should also mention that the mentioned dictionary will also be saved to an XML file to that the user can pick up all the settings they made at any time.

© Stack Overflow or respective owner

Related posts about c#

Related posts about timer