I am using the concise RateGate class to limit the number of requests I send to a server.
My code looks something like this:
var RateLimit = 35;
using(var RateGate = new RateGate(RateLimit, TimeSpan.FromSeconds(1)))
{
for(var Run = 1; Run <= 50; Run++)
{
for(var Batch = 0; Batch < 200; Batch++)
{
// Do some work, then...
MyClass MyClass;
if(MyClass.RateLimitHit)
{
RateLimit--;
}
RateGate.WaitToProceed();
}
}
}
Inside the if(MyClass.RateLimitHit)
, I need to lower the rate limit by 1. Not just the variable RateLimit
, but the limit running in the actual RateGate
.
In the RateGate class, I see this:
/// <summary>
/// Number of occurrences allowed per unit of time.
/// </summary>
public int Occurrences { get; private set; }
My question is: if I change private set;
to set;
and add RateGate.Occurrences = RateLimit;
after RateLimit--;
will this do what I want?
I tried it, but it looks like the RateGate
continues to execute at a max rate of 35/s.