Question about a System.Threading.Timer object and the "state" object you pass to it...

  • Thread starter Thread starter Paul Tomlinson
  • Start date Start date
P

Paul Tomlinson

Question about a System.Threading.Timer object and the "state" object you
pass to it...

Timer stateTimer = new Timer( = new TimerCallback( OnTimer ), o, 1000,
1000);

I have an array of timer objects which all fire into my OnTimer( object
state ) function very nicely. I pass in an object "o" on creation of this
timer which I subsequently get passed to me in my OnTimer function. Now in
the OnTimer function I want to modify the object "o" which I get passed back
and then have the modified version passed to me when every subsequent
interval fires.

Is this possible?
 
Hi,

Why you need the timer array? If you are calling the same method and passing
the same state why not use one timer only?

Now, regarding your question, the state will persist your changes, one VERY
important thing though, the delegate will be executed in a separate thread
meaning that you have to sync. the o object, with so many timers it may be
possible that you have two thread running the delegate at the same time,

again ,try to use only one Timer

Cheers,
 
Back
Top