mjohnson3091 Posted April 13, 2005 Posted April 13, 2005 Hi all, I'm trying to create a set of timers 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? 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!"); } Quote
Wile Posted April 13, 2005 Posted April 13, 2005 My guess would be that the sender object would point to the timer object that send the event. You can cast it to a timer (sender as Timer) to get the timer object that send the event. Quote Nothing is as illusive as 'the last bug'.
mjohnson3091 Posted April 13, 2005 Author Posted April 13, 2005 My guess would be that the sender object would point to the timer object that send the event. You can cast it to a timer (sender as Timer) to get the timer object that send the event. Thanks for the reply. I think that would give me a timer object, but as I was planning on storing them in a sorted list, each Timer would have the same name and an integer key as an ID. It's the integer key that I'm looking for. If I'm completely wrong in my understanding, please tell me how I can reference it back to the Sorted List and get the relevant ID. Thanks again. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.