0

I have an existing Java REST API that takes a file and passes it along to an S3 bucket for storage.

I've been given a C# Winforms desktop .NET Framework app (4.7). This app needs to take files (around 300+ JPEGs) from a user's specified folder and upload them each independently and asynchronously by calling a Java REST API "upload" endpoint. What is a proper way to make multiple async REST calls to C# so that I can report back to the user as each file gets uploaded and then when all of them have been uploaded?

I've thought about using a Parallel ForEach loop to process all the files and make a REST call for each, but wasn't sure if this was the most efficient approach or if I could properly get the feedback/progress needed as the files get uploaded and finished.

Andy
  • 1,243
  • 3
  • 22
  • 40
  • 1
    See these two methods to throttle async IO-bound tasks: [Throttling asynchronous tasks](https://stackoverflow.com/q/22492383/7444103). One uses the [TPL Dataflow](https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/dataflow-task-parallel-library) library. The other a pool of `SemaphoreSlim` + locking on the work items Queue (as a `HashSet`). Quite interesting. Both are meant to download data using HttpClient, so you can just turn it around to upload data instead. – Jimi Apr 29 '19 at 23:26
  • Awesome. Thank you. I'm researching on how to report back on progress for a progress bar, but these look promising. Also, here's a good explanation with diagrams: https://www.dotnetcurry.com/dotnet/886/image-resizing-dotnet-45-parallel-dataflow-library – Andy Apr 30 '19 at 00:17

0 Answers0