private void FillGrid(bool limit, List <long> explicitPatNums = null) { _dateTimeLastRequest = DateTime.Now; if (_fillGridThread != null) { return; } _dateTimeLastSearch = _dateTimeLastRequest; long billingType = 0; if (comboBillingType.SelectedIndex != 0) { billingType = DefC.Short[(int)DefCat.BillingTypes][comboBillingType.SelectedIndex - 1].DefNum; } long siteNum = 0; // if (!PrefC.GetBool(PrefName.EasyHidePublicHealth) && comboSite.SelectedIndex != 0) // { // siteNum = SiteC.List[comboSite.SelectedIndex - 1].SiteNum; // } DateTime birthdate = PIn.Date(textBirthdate.Text); //this will frequently be minval. if (birthdate == null) { return; } string clinicNums = ""; // if (!PrefC.GetBool(PrefName.EasyNoClinics)) // { // if (comboClinic.SelectedIndex == 0) // { // for (int i = 0; i < _listClinics.Count; i++) // { // if (i > 0) // { // clinicNums += ","; // } // clinicNums += _listClinics[i].ClinicNum; // } // } // else // { // clinicNums = _listClinics[comboClinic.SelectedIndex - 1].ClinicNum.ToString(); // } // } _fillGridThread = new ODThread(new ODThread.WorkerDelegate((ODThread o) => { PtDataTable = Patients.GetPtDataTable(limit, textLName.Text, textFName.Text, textHmPhone.Text, textAddress.Text, checkHideInactive.Checked, textCity.Text, textState.Text, textSSN.Text, textPatNum.Text, textChartNumber.Text, billingType, checkGuarantors.Checked, checkShowArchived.Checked, birthdate, siteNum, textSubscriberID.Text, textEmail.Text, textCountry.Text, textRegKey.Text, clinicNums, explicitPatNums, InitialPatNum); })); _fillGridThread.AddThreadExitHandler(new ODThread.WorkerDelegate((ODThread o) => { _fillGridThread = null; try { this.BeginInvoke((Action)(() => { FillGridFinal(limit); })); } catch (Exception) { } //do nothing. Usually just a race condition trying to invoke from a disposed form. })); _fillGridThread.AddExceptionHandler(new ODThread.ExceptionDelegate((e) => { try { this.BeginInvoke((Action)(() => { MessageBox.Show(e.Message); })); } catch (Exception) { } //do nothing. Usually just a race condition trying to invoke from a disposed form. })); _fillGridThread.Start(true); }