'throttling to limit throughput

So right now I'm trying to figure out how to solve this issue. I need to call an external resource (API) and pass to it an object collection.

So lets say, I have a sender like this:

public class Sender{

    /// Send an message to an external api
    public async Task Send(object[] objectCollection){
    
    }
}

To problem is, there is a throughput limit on the API side. For example (5 objects per second). So I need to implement some kind of a waiting mechanism on my side(throttler) that will work with concurrent method calls inside a single APP.

  1. Is there a .NET throttler already or do I have to implement it myself?
  2. How would you implement the 5 objects per second rule?

My idea was to simply use an semaphore but that would only limit the concurrency and not account for the time limit.

Thanks for suggestions.



Solution 1:[1]

So in the end, I used window sliding technique.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DavidWaldo