Render multiple SSRS reports in parallel This service takes in a report request object that can contain multiple reports that need to be rendered. This code works but I'm not sure if I've implemented anything wrong. Note the exportedImage.Result makes this synchronous but when I tried adding async and await to the Parallel.ForEach it doesn't seem to work so this was essentially a workaround, that's why I'm looking to figure out if I've implemented this correctly or not. _exporter.Export is an asynchronous method.
Just FYI, when I tried to add async and await, I added it like so:
await Task.Run(() =&gt; Parallel.ForEach(request.Reports, async report =&gt;
var exportedImage = await _exporter.Export(_reportServerUrl, reportPath, export, reportParameters);
var reportDictionary = new ConcurrentDictionary&lt;int, string&gt;();

await Task.Run(() =&gt; Parallel.ForEach(request.Reports, report =&gt;
{
    var (reportPath, bindingOrder, reportParameters) = report;
    
    var exportedImage = _exporter.Export(_reportServerUrl, reportPath, export, reportParameters);

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

    reportDictionary.GetOrAdd(bindingOrder, exportedImage.Result);
}));
Here's pure async example without any workarounds.
private async Task ProcessReport(Report report, ConcurrentDictionary&lt;int, string&gt; reportDictionary)
{
    var (reportPath, bindingOrder, reportParameters) = report;
    
    var exportedImage = await _exporter.Export(_reportServerUrl, reportPath, export, reportParameters);

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

    reportDictionary.GetOrAdd(bindingOrder, exportedImage);
}

var reportDictionary = new ConcurrentDictionary&lt;int, string&gt;();

List&lt;Task&gt; tasks = new List&lt;Task&gt;();
foreach (var report in request.Reports)
{
    tasks.Add(ProcessReport(report, reportDictionary));
}
await Task.WhenAll(tasks);