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
{{ message }}
Repository navigation
RateLimiter seems to hang with 1024 Permit Limit #105446
Timers run only once if their period is set to 0.
In the situation above, I clearly want the timer to repeat because I've provided a non-zero TimeSpan, but the timespan gets rounded down to Zero when the cast happens.
I think there are two potential ways to solve this. Either:
if(period is > TimeSpan.Zero && period < TimeSpan.FromMilliseconds(1)){
//Pick One:
period = TimeSpan.FromMilliseconds(1);
//OR
throw new ArgumentOutOfRangeException();
}
Personally, I think that setting the period to 1ms is the better option because that captures the intent of "I want this timer to run more than once" and does not push the range check down into user code.
Activity
dotnet-policy-service commentedon Jul 25, 2024
Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.
TonyValenti commentedon Jul 25, 2024
I've been digging into this more and it seems like the issue has something to do with the Timer not firing.
This will also demonstrate the issue.
You'll notice that the output should appear multiple times but it only shows once.
TonyValenti commentedon Jul 25, 2024
So I think I've found the issue with the Timer class.
In this code:
You'll notice this line:
Timers run only once if their period is set to 0.
In the situation above, I clearly want the timer to repeat because I've provided a non-zero TimeSpan, but the timespan gets rounded down to Zero when the cast happens.
I think there are two potential ways to solve this. Either:
Personally, I think that setting the period to 1ms is the better option because that captures the intent of "I want this timer to run more than once" and does not push the range check down into user code.
TonyValenti commentedon Jul 26, 2024
@vcsjones - Any thought about this?
BrennanConroy commentedon Aug 21, 2025
Using #109027 to track this issue now. It has some thoughts on what to change to fix this.