private void BwUpload_DoWork(object sender, DoWorkEventArgs e) { var importList = e.Argument as List <LaminationMaterialModel>; Dispatcher.Invoke(new Action(() => { txtStatus.Text = "Uploading ..."; prgStatus.Maximum = importList.Count(); })); int index = 1; foreach (var item in importList) { try { if (eAction == EExcute.AddNew) { LaminationMaterialController.Insert(item); dgLaminationMaterial.Dispatcher.Invoke(new Action(() => { dgLaminationMaterial.SelectedItem = item; dgLaminationMaterial.ScrollIntoView(item); })); Dispatcher.Invoke(new Action(() => { txtStatus.Text = "Importing ... "; prgStatus.Value = index; })); } else if (eAction == EExcute.Delete) { LaminationMaterialController.DeleteByOrderNoId(item.OrderNoId); laminationMatsSearchList.Remove(item); } e.Result = true; index++; } catch (Exception ex) { e.Result = false; Dispatcher.Invoke(new Action(() => { MessageBox.Show(ex.InnerException.InnerException.Message.ToString()); })); break; } } }