Problem with Timers in C# - Please help
Hi all,
I'm trying to create a set of timers (which will be dynamically sized) and store them in a SortedList identified with a number stored in a variable. All the timers will point to the same TimerElapsed handling code. Is there anyway to get the Elapsed code to recognise which timer elapsed or can someone suggest a better way to do it?
Thanks in advance.
// Called each time need to add a new timer.
System.Timers.Timer ClientTimer = new System.Timers.Timer();
ClientTimer.Enabled = true;
ClientTimer.Interval = 5000;
ClientTimer.Elapsed +=
new System.Timers.ElapsedEventHandler(ClientTimerTimeout);
mTimers.Add(mintClientID,ClientTimer);
The Timer Elapsed hadling code is below.
private void ClientTimerTimeout(object sender,
System.Timers.ElapsedEventArgs e)
{
System.Windows.Forms.MessageBox.Show("Elapsed!",
"Timer Event Raised!");
}