public async Task <int> ProcessPendingEvents() { using var log = BeginFunction(nameof(EventProcessorMicroService), nameof(ProcessPendingEvents)); try { var totalCount = 0; int iterationCount; do { iterationCount = 0; iterationCount += await CommunicationMicroService.ProcessEventsAsync(); iterationCount += await FulfillmentMicroService.ProcessEventsAsync(); iterationCount += await FundingMicroService.ProcessEventsAsync(); iterationCount += await InventoryMicroService.ProcessEventsAsync(); iterationCount += await OrderMicroService.ProcessEventsAsync(); iterationCount += await SquareMicroService.ProcessEventsAsync(); iterationCount += await UserMicroService.ProcessEventsAsync(); //Task<int>[] tasks = { //CommunicationMicroService.ProcessEventsAsync(), //FulfillmentMicroService.ProcessEventsAsync(), //FundingMicroService.ProcessEventsAsync(), //InventoryMicroService.ProcessEventsAsync(), //OrderMicroService.ProcessEventsAsync(), //PayPalMicroService.ProcessEventsAsync(), //SquareMicroService.ProcessEventsAsync(), //UserMicroService.ProcessEventsAsync() }; //var counts = await Task.WhenAll(tasks); //iterationCount = counts.Sum(); totalCount += iterationCount; } while (iterationCount > 0); var result = totalCount; log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }