Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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!");
}

Posted
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.
Nothing is as illusive as 'the last bug'.
Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...