public static void SendCommand(this Control control, List <ConnectionRow> connections, bool errorsInRow, CommandMetaData commandMetaData, params object[] args) { using (ProgressDialog dialog = new ProgressDialog() { ProgressMessage = $"Sending command to {connections.Count} devices.", Style = ProgressBarStyle.Marquee, CancelButtonEnabled = false, }) { Thread thread = new Thread(() => { Parallel.ForEach(connections, (connection) => { string messageString = ""; CommunicationProcessResult result; do { Reporter reporter = new Reporter(); CommandProcess process = new CommandProcess(connection.Connection, reporter, new CommandCallback(commandMetaData.GetMessage(args)), 100, 3); result = process.Send(); StringBuilder fullMessageString = new StringBuilder(); fullMessageString.AppendLine("Error while communicating with " + connection.Connection.Settings.GetDeviceDescriptor() + "."); fullMessageString.AppendLine(); fullMessageString.Append("Failed to confirm command: " + commandMetaData.OscAddress); messageString = fullMessageString.ToString(); if (result != CommunicationProcessResult.Success && errorsInRow == true) { connection.SetError(messageString); } }while (result != CommunicationProcessResult.Success && errorsInRow == false && dialog.InvokeShowError(messageString, MessageBoxButtons.RetryCancel) == DialogResult.Retry); }); control.Invoke(new MethodInvoker(dialog.Close)); }); thread.Start(); dialog.ShowDialog(control); } }