Dynamically Create Timers are Run-Time

G

GoneRural

Hello,

I am trying to figure out how to create multiple timers at run-time
(which could vary each time) that I can then reference? Basically I
have a service that will check a registry key and each subkey under
that registry key will require a timer in which each subkey will
contain a couple of settings such as the timer interval and job name.
I can enumerate and read the registry no problem, but I am unclear how
to create a timer for each one of those subkeys and then be able to
reference that timer setting it's interval based on the setting in the
registry for that job. I know I can add the handlers to it and use the
sender to determine which timer has fired, but the creation of the
timers dynamically like that and understanding how they would be
referenced is what confuses me.

Can anyone help me with some sample code on how this could be done. I
have been continuously searching for the answer but have not found
anything that would help me.

Thanks in advance for your help,
Ron
 
C

Chris

GoneRural said:
Hello,

I am trying to figure out how to create multiple timers at run-time
(which could vary each time) that I can then reference? Basically I
have a service that will check a registry key and each subkey under
that registry key will require a timer in which each subkey will
contain a couple of settings such as the timer interval and job name.
I can enumerate and read the registry no problem, but I am unclear how
to create a timer for each one of those subkeys and then be able to
reference that timer setting it's interval based on the setting in the
registry for that job. I know I can add the handlers to it and use the
sender to determine which timer has fired, but the creation of the
timers dynamically like that and understanding how they would be
referenced is what confuses me.

Can anyone help me with some sample code on how this could be done. I
have been continuously searching for the answer but have not found
anything that would help me.

Thanks in advance for your help,
Ron

Make an array list and throw the timers into the array list. Then you
can itterate through you arraylist to see each and every one of your times.

Dim Arr as new ArrayList
Dim T as New Timer
With T
'Set methods
End With

Arr.Items.Add(T)

Chris
 
G

GoneRural

Excellent, thanks I will give this a try and see how that works. I
appreciate the help.

Ron
 
G

GoneRural

Ok, that works great for creating the array of timers I need based on
number of keys it detects. My last question would be how I can
determine which timer belongs to which job? Should I create a class
which inherits the timer and then add a "tag" and "execute" property so
to speak that I would set the name of the job and the command to
execute when the time elapses?

Thanks again for the help,
Ron
 

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

Similar Threads


Top