C#C
C#3y ago
PatrickG

❔ feedback on clientside api request limiter

Hello I just want to know if this is a good way of limiting requests made by a client to a public API.
Is there a better way to do it ??

public static class Limit
{
static List<DateTime> requests = new List<DateTime>();

static public bool WaitForConstraint()
{
requests = requests.Where(x => x >= DateTime.Now.AddSeconds(-10)).ToList();
while (requests.Count > 150)
{
requests = requests.Where(x => x >= DateTime.Now.AddSeconds(-10)).ToList();
Console.WriteLine("throttleing requests.");
}
requests.Add(DateTime.Now);
return true;
}
}
Was this page helpful?