❔ Returning an async dictionary ?I am calling this function from an api endpoint and want to return the results from the tasks. Right now I store all results in a dictionary but am returning a Task. Is there a better way to do this so that I just return the result as a plain dictionary instead of a Task ?
public class DataGatherer
{
static async Task<Dictionary<string, object>> GetData()
{
Dictionary<string, object> dict = new Dictionary<string, object>();
using HttpClient client = new();
try
{
var tasks = new Task[] {
Task.Run(async () => await ExternalTablesGatherer.ProcessRepositoriesAsync(client, "6382963", dict)),
Task.Run(async () => await QueueDataGatherer.GetDataAsync(client, "6010081", dict))
};
await Task.WhenAll(tasks);
return dict;
}
catch (Exception exception)
{
Console.WriteLine(exception);
return null;
}
}
}