How to wait for the result while controller is making parallel call
问题 I am trying to find account details from DB (GetAccountDetailAsync) for an array of accounts and would like to run in parallel to make it faster. [HttpPost] public async Task<IHttpActionResult> GetAccountsAsync(IEnumerable<int> accountIds) { var resultAccounts = new List<AccountDetail>(); var task = Task.Run(() => { Parallel.ForEach(accountIds, new ParallelOptions { MaxDegreeOfParallelism = 5 }, async accountId => { var response = await GetAccountDetailAsync(accountId).ConfigureAwait(false);