File tree 1 file changed +14
-1
lines changed
1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -102,6 +102,9 @@ private async Task RunCallbackAsync()
102
102
return ;
103
103
}
104
104
105
+ // If the callback runs before the next time, then store it here before we reset it and use it for scheduling.
106
+ DateTime ? nextTimeOverride = null ;
107
+
105
108
if ( isTraceLogLevelEnabled ) _logger . LogTrace ( "Starting RunCallbackAsync" ) ;
106
109
using ( await _lock . LockAsync ( ) . AnyContext ( ) )
107
110
{
@@ -115,6 +118,13 @@ private async Task RunCallbackAsync()
115
118
}
116
119
117
120
_last = SystemClock . UtcNow ;
121
+ if ( SystemClock . UtcNow < _next )
122
+ {
123
+ _logger . LogWarning ( "ScheduleNext RunCallbackAsync was called before next run time {NextRun:O}, setting next to current time and rescheduling" , _next ) ;
124
+ nextTimeOverride = _next ;
125
+ _next = SystemClock . UtcNow ;
126
+ _shouldRunAgainImmediately = true ;
127
+ }
118
128
}
119
129
120
130
try
@@ -147,7 +157,10 @@ private async Task RunCallbackAsync()
147
157
if ( isTraceLogLevelEnabled ) _logger . LogTrace ( "Finished sleeping" ) ;
148
158
}
149
159
150
- var nextRun = SystemClock . UtcNow . AddMilliseconds ( 10 ) ;
160
+ var nextRun = SystemClock . UtcNow . AddMilliseconds ( 10 ) ;
161
+ if ( nextRun < nextTimeOverride )
162
+ nextRun = nextTimeOverride . Value ;
163
+
151
164
if ( _shouldRunAgainImmediately || next . HasValue && next . Value <= nextRun )
152
165
ScheduleNext ( nextRun ) ;
153
166
else if ( next . HasValue )
You can’t perform that action at this time.
0 commit comments