You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The general scenario I am trying to understand is this: Suppose a ITimer has been scheduled to invoke a callback every 1. second, but callbacks are delayed e.g., by 3. seconds, such that the timer will invoke the callback 3 times when it finally gets allocated processor time (i.e. emulated by calling FakeTimeProvider.Advance(3 seconds). Normally, the callback would just be invoked 3 times and the next invocation will then get scheduled.
But what if the timer period is changed by the callback, e.g. during the first of the three callbacks? Does it influence the remaining two callbacks that have been scheduled to happen or does it just have an effect after the three callbacks are done? What does the real System.Threading.Timer do in this case?
Consider this test case. What should the expectedCallbackCount be set to in each of the scenarios?
[Theory][InlineData(Timeout.Infinite,Timeout.Infinite,???)][InlineData(1000,500,???)][InlineData(1000,2000,???)][InlineData(2000,1000,???)][InlineData(500,1000,???)]
public void Timer_changed_during_callback_while_advancing(intdueTimeMs,intperiodMs,intexpectedCallbackCount){vartimeProvider=newFakeTimeProvider();varcallbackCount=0;ITimertimer=default!;timer=timeProvider.CreateTimer(
_ =>{callbackCount++;if(callbackCount==1){timer.Change(TimeSpan.FromMilliseconds(dueTimeMs),TimeSpan.FromMilliseconds(periodMs));}},null,TimeSpan.FromMilliseconds(1000),TimeSpan.FromMilliseconds(1000));timeProvider.Advance(TimeSpan.FromMilliseconds(3000));Assert.Equal(callbackCount,expectedCallbackCount);}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi @sebastienros, @geeknoid, @danmoseley, @RussKie, et al.
The general scenario I am trying to understand is this: Suppose a
ITimer
has been scheduled to invoke a callback every 1. second, but callbacks are delayed e.g., by 3. seconds, such that the timer will invoke the callback 3 times when it finally gets allocated processor time (i.e. emulated by callingFakeTimeProvider.Advance(3 seconds)
. Normally, the callback would just be invoked 3 times and the next invocation will then get scheduled.But what if the timer period is changed by the callback, e.g. during the first of the three callbacks? Does it influence the remaining two callbacks that have been scheduled to happen or does it just have an effect after the three callbacks are done? What does the real
System.Threading.Timer
do in this case?Consider this test case. What should the
expectedCallbackCount
be set to in each of the scenarios?Beta Was this translation helpful? Give feedback.
All reactions