PC Review


Reply
Thread Tools Rate Thread

Array of System.Timers.timer - Assigning an object to timer

 
 
Gina_Marano
Guest
Posts: n/a
 
      7th Mar 2007
Good day,

I read 1-n records from a database, For each record in the database I
create a system timer. (then add the timer to a list of timers).

I create an object to store the data for each record in:

public class CustAckAttribs
{
public int CustomerID;
...
}

When the timer elapses how do I know what data to use? How do I assign
the specific object to the timer created for it?

thanks

~Gina_M~

 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      7th Mar 2007
Well, you could hook the timer's event to a method on the class in
question (or a proxy) - but I must say: that sounds like a lot of
timers... something akin to below. Note also that "as is" this will
prevent custAck from being garbage collected until it has fired... you
might want a WeakReference in there somewhere...

CustAckAttribs custAck = new CustAckAttribs();
Timer timer = new Timer(TIMEOUT);
globalTimers.Add(Timer);
// using a proxy (inline delegate will serve quite nicely)
timer.Elapsed += delegate {
custAck.TimerElapsed1();
};
// using direct method
timer.Elapsed += custAck.TimerElapsed2;

 
Reply With Quote
 
Gina_Marano
Guest
Posts: n/a
 
      8th Mar 2007
Thanks Marc,

This and a previous post that was answered got me there. If I can
cleanup (and take out anything priorietary) I will post the solution
here.

~Gina_M~

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
System.Threading.Timer vs System.Timers.Timer RK Microsoft Dot NET Framework 2 13th Jan 2006 04:01 PM
Application object and System.Timers.Timer Shawn B. Microsoft ASP .NET 2 28th Apr 2005 08:20 PM
System.Timers.Timer bug : timer fires immediately/continously felix Microsoft Dot NET Framework 2 25th Apr 2005 06:48 PM
System.Timers.Timer/System.Threading.Timer Not Firing At All on Dev Server james.e.coleman@gmail.com Microsoft ASP .NET 1 22nd Feb 2005 09:41 PM
RE: Timers not fireing System.Windows.Forms.Timer and System.Timer =?Utf-8?B?VGlt?= Microsoft Dot NET Framework Forms 0 18th Aug 2004 11:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:39 PM.