I have created an array of timers (1-n). At first I just created
windows form timers but I read that system timers are better for
background work. The timers will just be monitoring different
directories and updating a database. No interaction with the GUI.
Problem is that the system timers do not have a tag property so I can
tie in an object.
example (old way):
public class TimerInfo
{
public string sPath;
public int iInterval;
}
private ArrayList arrTimers = new ArrayList();
private void CreateTimers(in t NUMBER_TIMERS)
{
TimerInfo Info;
System.Timers.T imer newTimer;
for (int i = 1; i <= NUMBER_TIMERS; i++)
{
Info = new TimerInfo();
Info.sPath = "c:\\";
Info.iInterval = 60000;
newTimer = new System.Timers.T imer();
newTimer.Elapse d += timerWatch_Tick ;
newTimer.Interv al = 20000;
newTimer.Tag = TimerInfo;
newTimer.Enable d = true;
arrTimers.Add(n ewTimer);
}
}
private void timerWatch_Tick (object sender, EventArgs e)
{
string sPath = ((TimerInfo)((T imer)sender).Ta g).sPath;
CheckForFile(sP ath);
}
Do I need to call Dispose if I want to reset the timer array?
foreach (System.Timers. Timer atimer in arrTimers)
{
atimer.Dispose( );
}
arrTimers.Clear ();
Thanks for your help. I am struggling as a newbie through C# even
though it is a really neat language.
~Gina~
windows form timers but I read that system timers are better for
background work. The timers will just be monitoring different
directories and updating a database. No interaction with the GUI.
Problem is that the system timers do not have a tag property so I can
tie in an object.
example (old way):
public class TimerInfo
{
public string sPath;
public int iInterval;
}
private ArrayList arrTimers = new ArrayList();
private void CreateTimers(in t NUMBER_TIMERS)
{
TimerInfo Info;
System.Timers.T imer newTimer;
for (int i = 1; i <= NUMBER_TIMERS; i++)
{
Info = new TimerInfo();
Info.sPath = "c:\\";
Info.iInterval = 60000;
newTimer = new System.Timers.T imer();
newTimer.Elapse d += timerWatch_Tick ;
newTimer.Interv al = 20000;
newTimer.Tag = TimerInfo;
newTimer.Enable d = true;
arrTimers.Add(n ewTimer);
}
}
private void timerWatch_Tick (object sender, EventArgs e)
{
string sPath = ((TimerInfo)((T imer)sender).Ta g).sPath;
CheckForFile(sP ath);
}
Do I need to call Dispose if I want to reset the timer array?
foreach (System.Timers. Timer atimer in arrTimers)
{
atimer.Dispose( );
}
arrTimers.Clear ();
Thanks for your help. I am struggling as a newbie through C# even
though it is a really neat language.
~Gina~
Comment