C# Telegram Bot Timing Out: How Can I Fix the Request Timeout?

My C# Telegram bot times out when posting multiple images. What’s a remedy? Try this code:

public async Task SendPics(){foreach(var item in Repo.GetImages())await Api.Upload(item.Group,new FileData(item.Path,new MemoryStream(item.Content)));}

My experience with similar issues has been in balancing asynchronous tasks when dealing with multiple large files. I solved it by limiting how many requests ran concurrently. I implemented a throttling mechanism with a SemaphoreSlim to restrict the number of simultaneous uploads. This approach prevented the client from overloading the API and avoided the device timing out. In addition, verifying that the network timeout settings are sufficient for longer running operations also helped, as sometimes the default settings aren’t adequate for several sequential or parallel uploads.