Skip to main content
2 of 2
deleted 23 characters in body
aepot
  • 2.1k
  • 9
  • 20

Here's pure async example without any workarounds.

private async Task ProcessReport(Report report, ConcurrentDictionary<int, string> reportDictionary)
{
    var (reportPath, bindingOrder, reportParameters) = report;
    
    var exportedImage = await _exporter.Export(_reportServerUrl, reportPath, export, reportParameters);

    if (exportedImage == null)
    {
        throw new InvalidOperationException($"Could not render report {reportIdentifier} with binding order {bindingOrder}.");
    }

    reportDictionary.GetOrAdd(bindingOrder, exportedImage);
}
var reportDictionary = new ConcurrentDictionary<int, string>();

List<Task> tasks = new List<Task>();
foreach (var report in request.Reports)
{
    tasks.Add(ProcessReport(report, reportDictionary));
}
await Task.WhenAll(tasks);
aepot
  • 2.1k
  • 9
  • 20