private void bwWorker_Completed(object sender, RunWorkerCompletedEventArgs e) { if (_frmProgress != null) { _frmProgress.Hide(); _frmProgress = null; } if (e.Error != null) { new MessageBox.MessageBoxBA().Show(this, "Có lỗi trong quá trình xử lý dữ liệu. [" + e.Error.Message + "]"); } }
protected override object GetData() { //Dùng backgroundworker để chia nhỏ dữ liệu lấy lên giao diện! DateTime fromDate = ipFromDate.DateTime; DateTime toDate = ipToDate.DateTime; if ((toDate - fromDate).TotalHours > 1) { lbMessage.Visible = false; lblMsg.Text = "Bạn chỉ được tìm kiếm trong khoảng thời gian 1 giờ đồng hồ"; ipFromDate.Focus(); return(new object()); } else { lbMessage.Visible = true; lblMsg.Text = ""; } BackgroundWorker bwWorker = new BackgroundWorker(); bwWorker.DoWork += bwWorker_DoWork; bwWorker.RunWorkerCompleted += bwWorker_Completed; _frmProgress = new frmProgressBar(); bwWorker.RunWorkerAsync(); //Lock up the UI with this modal progress form. try { _frmProgress.ShowDialog(this); _frmProgress = null; this.Activate(); this.MinimizeBox = false; } catch (Exception ex) { new MessageBox.MessageBoxBA().Show(ex.ToString(), "Thông báo", MessageBox.MessageBoxButtonsBA.OK, MessageBox.MessageBoxIconBA.Error); } return(_lstData); }