G
Gina_Marano
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(int NUMBER_TIMERS)
{
TimerInfo Info;
System.Timers.Timer newTimer;
for (int i = 1; i <= NUMBER_TIMERS; i++)
{
Info = new TimerInfo();
Info.sPath = "c:\\";
Info.iInterval = 60000;
newTimer = new System.Timers.Timer();
newTimer.Elapsed += timerWatch_Tick;
newTimer.Interval = 20000;
newTimer.Tag = TimerInfo;
newTimer.Enabled = true;
arrTimers.Add(newTimer);
}
}
private void timerWatch_Tick(object sender, EventArgs e)
{
string sPath = ((TimerInfo)((Timer)sender).Tag).sPath;
CheckForFile(sPath);
}
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(int NUMBER_TIMERS)
{
TimerInfo Info;
System.Timers.Timer newTimer;
for (int i = 1; i <= NUMBER_TIMERS; i++)
{
Info = new TimerInfo();
Info.sPath = "c:\\";
Info.iInterval = 60000;
newTimer = new System.Timers.Timer();
newTimer.Elapsed += timerWatch_Tick;
newTimer.Interval = 20000;
newTimer.Tag = TimerInfo;
newTimer.Enabled = true;
arrTimers.Add(newTimer);
}
}
private void timerWatch_Tick(object sender, EventArgs e)
{
string sPath = ((TimerInfo)((Timer)sender).Tag).sPath;
CheckForFile(sPath);
}
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~