private async void PayNowButton_Click(object sender, RoutedEventArgs e) { MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure?", "Pay Confirmation", MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.Yes) { using (new WaitCursor()) { var arkClientsToPay = (ArkClientsListView.ItemsSource as List <ArkClientModel>); if (!arkClientsToPay.Any()) { MessageBox.Show("No clients to pay"); } else { var payClientTasks = new List <Task <ErrorIndexModel> >(); foreach (var clientToPay in arkClientsToPay) { _log.Info(String.Format("Attempting to pay {0}({1}) to address {2}", (clientToPay.AmountToBePaid / StaticProperties.ARK_DIVISOR), (long)clientToPay.AmountToBePaid, clientToPay.Address)); payClientTasks.Add(PayoutService.PayClient(clientToPay, _passPhrase, PaymentDescriptionTextBox.Text)); } var errors = await Task.WhenAll(payClientTasks); if (errors.SelectMany(x => x.ErrorClients).Any()) { MessageBox.Show("Error paying some clients. Check log for details"); } else { MessageBox.Show("Finished paying clients without errors. Check log for details"); ArkClientsListView.ItemsSource = new List <ArkClientModel>(); ArkClientsListView.Tag = null; Refresh(); } } } } }