Hi Gina
"The System.Timers.T imer Timers do not have a Tag property"
Yes they do have a tag property, i just checked and a timer has the tag.
I get what yiu are doing as i do something similar in my app. You have a
load of timers in an array and you want to know when a particular timer has
finished or its time has elapsed?
As i said they do have a tag property so i am confused about you saying that
or why you dont think they have one?
In my situation i did this:
Make a TimerManager class
Make a MyTimer class (or some better app specific name)
Now in your MyTimer class do this
class MyTimer : Timer //and inherit from timer
Now you can add any attributes you like to your timer and it will have all
the functionality of the normal timer.
so if you have an enumerator such as (just using examples of timer
categories)
enum TimerType : int
{
LunchBreak,
ClassLength
}
You could then do this in MyTimer class
class MyTimer : Timer
{
TimerType _myTimerType;
public event timerElapsed;
public delegate timerElapsed TimeElapsed(Tim erType t);
MyTimer(TimerTy pe t)
{
_myTimerType = t;
Elapsed += OnTimerElapsed; //.net 2 syntax
}
public TimerType
{
get{return _myTimerType; }
}
public void OnTimerElapsed( object sender,
System.Timers.E lapsedEventArgs e)
{
timerElapsed(_m yTimerType);
}
}
Then in your TimerManager class do this
class TimerManager
{
private ArrayList MyTimerList;
TimerManager(){ };
//create timers
public void CreateTimer(Tim erType t, int interval);
{
MyTimer m = new MyTimer(t);
m.Interval = interval;
m.timerElapsed += TimerComplete;
MyTimerList.Add (m);
}
public void TimerComplete(T imerType t)
{
switch(t)
{
case LunchBreak:
//do something
break;
case ClassLength:
//do something
break;
}
}
}
I have written that off the top of my head so i dont know if it will compile
but i hope it gives you an idea of one implementation method? By doing that
you wrap up the timer to have functionality you need and only ever need the
TimerManager. So to create a timer from some outside class:
TimerManager tm = new TimerManager();
tm.CreateTimer( TimerType.Lunch Break);
Of course you need to add methods to the timer manager class for starting
the timers, or have them start the moment they are created and similarly the
same for stopping them, just a foreach to iterate through the array would do
it.
So the idea is the enumerator makes each timer you create unique. You can
easily adjust to pass more data from the MyTimer into the TimerComplete and
this allows a central manegemt of all the timers. So the TimerComplete in
the case above will fire everytime any timer elapsed its interval and then
it checks which timer it was and you can react as you see fit.
Thats the way i did what i think you are trying to do. Does that help at
all?
"Gina_Maran o" <gi*******@gmai l.comwrote in message
news:11******** *************@m 7g2000cwm.googl egroups.com...
Hi Daniel:
I currently have an arraylist of System.Timers.T imer Timers.
The System.Timers.T imer Timers do not have a Tag property.I use the tag
property of the Timer to store an object so that on the tick/elapse
event I can get timer specific settings.
I am open to any ideas. I read that System.Timers.T imer Timers are the
timers to use since it does not interact with the GUI at all.
Please ask as many questions as you wish. I am new to C# and probably
don't always use the correct terminology.
~Gina~
Daniel wrote:
>Are you saying you want a timer object that does not have a tag info? Or
a
object that has everything a timer has and also has a tag object?
"Gina_Marano " <gi*******@gmai l.comwrote in message
news:11******* *************** @m73g2000cwd.go oglegroups.com. ..
>I better clearly state my main question (besides maybe a code review)
is:
Is there a trick so I can assign an object to a system timer since it
does not have a tag field?