void btnReconnect_Click(object sender, EventArgs e) { fgSVM = new FormGenerateSVMProgress(); fgSVM.SetProgressStyle(ProgressBarStyle.Marquee); using (BackgroundWorker bw = new BackgroundWorker()) { bw.DoWork += (senderM, eM) => { this.Cursor = Cursors.WaitCursor; try { var processName = Properties.Settings.Default.ProcessName.ToString(); if (!String.IsNullOrEmpty(processName)) { StartService(); bool finished = client.Reconnect(processName); if (finished) { _paneSVM.EnableReviewButton(processName[0].ToString()); } } else { MessageBox.Show(this, "No process to reconect to!", "Process don't exists", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch { MessageBox.Show(this, "Unable to reconnect to server!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }; bw.RunWorkerCompleted += (senderM, em) => { this.Cursor = Cursors.Default; fgSVM.Close(); fgSVM.Dispose(); }; bw.RunWorkerAsync(); fgSVM.ShowDialog(); }; }