private void SetText(string btn_Text) { // InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true. if (this.btn_LoadPatient.InvokeRequired) { LoadPatientDelegate d = new LoadPatientDelegate(SetText); this.Invoke(d, new object[] { btn_Text }); } else { this.btn_LoadPatient.Enabled = true; this.btn_LoadPatient.Text = btn_Text; loading = false; bgw.Dispose(); progressBar1.Visible = false; progressBar1.Value = 0; } }