Search code examples
c#plinq

Multiple REST API requests using PLinq


I'm trying to clean this up so experts can help me move forward.

as "svik" suggested below, after all the tasks are completed, I have a HTTPResponseMessage[].

How do I know what response was for what request?

var tasks = File.ReadLines(filepath).Select(url => client.GetAsync(url));
var results = await Task.WhenAll(tasks);

Solution

  • PLINQ doesn't work well with asynchronous operations. But you don't actually need PLINQ here:

    var tasks = File.ReadLines(filepath).Select(url => client.GetAsync(url));
    var results = await Task.WhenAll(tasks);
    

    This will start all the tasks serially, but they then continue to run in parallel.