tags:

views:

489

answers:

3

If I call Threading.Timer.Change() twice in a row, when will the thread next run?

For example:

myTimer.Change(5000, Timeout.Infinite);
// Only 2 seconds pass.
myTimer.Change(5000, Timeout.Infinite);

After this, will the thread next run in 3 seconds or 5 seconds?

I hope the answer is the latter, that the timer is reset with each call of Change(). If not, I'll need to find a way around this.

+4  A: 

It will run in 5 seconds. Calling Change will Reset the initial Count.

JaredPar
Thank you for your help.
joshdick
+2  A: 

Not according to this post: http://social.msdn.microsoft.com/Forums/en-US/netfxcompact/thread/0cce7729-be65-45da-a9e2-bda3893d84f2 It says your timer callback may get called when you call Change().

Bo Skjoett
That's System.Windows.Forms.Timer, no System.Threading.Timer
vasek7
A: 

Bo, you're misinterpreting the answer in that other thread. Quote:

one or even several callbacks are already queued so they will eventually be executed

That doesn't mean that Change() won't reset the time for newly generated events. Only that there might still be old ones, that were not processed yet.

paul