I have a written an application in c# that receives a request from another application and sends a request to an external broker via HTTP. broker accepts only 40 requests at a time. so I have a config where I mention the count. Broker is asking us to send 40 requests in one batch and another 40 in another batch but there should be a gap of 5 seconds. my question is how to call a method at a specific time . Presently 2 batches each with 40 requests go at the same time. My Present code looks like this. I need some idea how can I handle this.. Help will be highly appreciated. thanks.
if (requestBatchesByAccount.TryGetValue(locate.account, out BatchRequestInfo batch) == false)
{
batch = new BatchRequestInfo();
}
batch.locates.Add(locate);
requestBatchesByAccount[locate.account] = batch;
if (batch.locates.Count == maxBatchSize)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(RequestStockLoanBatch), batch);
requestBatchesByAccount.Remove(locate.account);
}
Add the following code before calling the method:
await Task.Delay(5000);
And add async
to the method that contains it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.