0

Very puzzled about timers, they don't seem to be working correctly.

I've created a timer like this:

this._catTimer = new Timer(state => this.catTimer_Tick(null, new EventArgs()), null, 0, Timeout.Infinite);

It ticks once immediately. At the end of the callback I have this:

this._catTimer.Change(5000, Timeout.Infinite);

But my timer never ticks again. This line is reached.

I've tried it with 5000, 0 too but it never ticks again. Any ideas?

0

3 Answers 3

1

You are giving Timeout.Infinite for the period argument in both constructor (public Timer(TimerCallback callback, Object state, uint dueTime, uint period)) and Change( int dueTime, int period) method which mean you never want the periodic signalling.

period

The time interval between invocations of the callback method specified when the Timer was constructed, in milliseconds. Specify Timeout.Infinite to disable periodic signaling, MSDN.

Sign up to request clarification or add additional context in comments.

Comments

0

Try putting a try/catch around the logic in catTimer_Tick method. Maybe your code is never reaching .Change line.

Comments

0

Have fixed this, it was caused by another thread that was blocking. You'd not think a threading timer would be affected by this but it was.

1 Comment

How were the threads synchronized? Did they use the same SynchronizationObject?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.