C#
C#

help

Root Question Message

Cliff Karlsson
Cliff Karlsson11/17/2022
❔ 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;
            }
        }
    }
Message Not Public

Sign In and Join Server To See

11/17/2022
Message Not Public

Sign In and Join Server To See

11/17/2022
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy