private void buttonSendMessage_Click(object sender, EventArgs e) { String messageToSend = this.richTextBoxMessageToSend.Text.Trim(); if (messageToSend == "") return; if (isSendingMessage) return; this.buttonSendMessage.Enabled = false; isSendingMessage = true; asyncWorder= new BackgroundWorker(); asyncWorder.DoWork += new DoWorkEventHandler(SendMessageAsync); asyncWorder.RunWorkerCompleted +=new RunWorkerCompletedEventHandler(SendMessageCompleted); frmProgress = new FrmProgress(); asyncWorder.RunWorkerAsync(new object[] { OrdersDataTable, messageToSend }); frmProgress.StartPosition = FormStartPosition.CenterScreen; frmProgress.ShowDialog(this); frmProgress = null; }
private void SyncOrderData() { if (isSyncingData) { return; } this.buttonSyncEbayData.Enabled = false; isSyncingData = true; DateTime startDate = this.dateTimePickerStartTime.Value; DateTime endDate = this.dateTimePickerEndTime.Value; startDate = startDate.ToUniversalTime(); endDate = endDate.ToUniversalTime(); asyncWorder = new BackgroundWorker(); asyncWorder.DoWork += new DoWorkEventHandler(GetDataAsync); asyncWorder.RunWorkerCompleted += new RunWorkerCompletedEventHandler(GetDataCompleted); frmProgress = new FrmProgress(); asyncWorder.RunWorkerAsync(new object[] { startDate, endDate }); frmProgress.StartPosition = FormStartPosition.CenterScreen; frmProgress.ShowDialog(this); frmProgress = null; }
private void buttonSendMessage_Click(object sender, EventArgs e) { String messageToSend = this.richTextBoxMessageToSend.Text.Trim(); if (messageToSend == "") { return; } if (isSendingMessage) { return; } this.buttonSendMessage.Enabled = false; isSendingMessage = true; asyncWorder = new BackgroundWorker(); asyncWorder.DoWork += new DoWorkEventHandler(SendMessageAsync); asyncWorder.RunWorkerCompleted += new RunWorkerCompletedEventHandler(SendMessageCompleted); frmProgress = new FrmProgress(); asyncWorder.RunWorkerAsync(new object[] { OrdersDataTable, messageToSend }); frmProgress.StartPosition = FormStartPosition.CenterScreen; frmProgress.ShowDialog(this); frmProgress = null; } // buttonSendMessage_Click
} // GetMessagesAsync private void GetDataCompleted(object sender, RunWorkerCompletedEventArgs e) { // The background process is complete. First we should hide the // modal Progress Form to unlock the UI. The we need to inspect our // response to see if an error occurred, a cancel was requested or // if we completed successfully. if (frmProgress != null) { frmProgress.Hide(); frmProgress = null; } // Check to see if an error occurred in the // background process. if (e.Error != null) { MessageBox.Show(e.Error.Message); return; } object[] fetchedCnts = (object[])e.Result; // Check to see if the background process was canceled. if (e.Cancelled) { MessageBox.Show(String.Format("操作取消!共更新 {0} 个订单,{1} 个消息", (int)fetchedCnts[0], (int)fetchedCnts[1]), "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); this.buttonSyncEbayData.Enabled = true; asyncWorder = null; return; } // Everything completed normally. // process the response using e.Result MessageBox.Show(String.Format("恭喜!下载ebay订单完成,共更新 {0} 个订单, 下载 {1} 个新消息 .", (int)fetchedCnts[0], (int)fetchedCnts[1]), "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); this.buttonSyncEbayData.Enabled = true; asyncWorder = null; LoadData(); isSyncingData = false; }
} // SendMessageAsync private void SendMessageCompleted(object sender, RunWorkerCompletedEventArgs e) { if (frmProgress != null) { frmProgress.Hide(); frmProgress = null; } // Check to see if an error occurred in the // background process. if (e.Error != null) { MessageBox.Show(e.Error.Message); return; } int sentMessageCnt = (int)e.Result; // Check to see if the background process was canceled. if (e.Cancelled) { MessageBox.Show(String.Format("操作取消!共发送 {0} 个消息", sentMessageCnt), "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); this.buttonSendMessage.Enabled = true; asyncWorder = null; return; } // Everything completed normally. // process the response using e.Result MessageBox.Show(String.Format("恭喜!发送消息成功,共发送 {0} 个消息 .", sentMessageCnt), "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); this.buttonSendMessage.Enabled = true; asyncWorder = null; isSendingMessage = false; MessageSent = true; } // SendMessageCompleted
private void SendMessageCompleted(object sender, RunWorkerCompletedEventArgs e) { if (frmProgress != null) { frmProgress.Hide(); frmProgress = null; } // Check to see if an error occurred in the // background process. if (e.Error != null) { MessageBox.Show(e.Error.Message); return; } int sentMessageCnt = (int)e.Result; // Check to see if the background process was canceled. if (e.Cancelled) { MessageBox.Show(String.Format("操作取消!共发送 {0} 个消息", sentMessageCnt), "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); this.buttonSendMessage.Enabled = true; asyncWorder = null; return; } // Everything completed normally. // process the response using e.Result MessageBox.Show(String.Format("恭喜!发送消息成功,共发送 {0} 个消息 .", sentMessageCnt), "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); this.buttonSendMessage.Enabled = true; asyncWorder = null; isSendingMessage = false; MessageSent = true; }
private void SyncOrderData() { if (isSyncingData) return; this.buttonSyncEbayData.Enabled = false; isSyncingData = true; DateTime startDate = this.dateTimePickerStartTime.Value; DateTime endDate = this.dateTimePickerEndTime.Value; startDate = startDate.ToUniversalTime(); endDate = endDate.ToUniversalTime(); asyncWorder = new BackgroundWorker(); asyncWorder.DoWork += new DoWorkEventHandler(GetDataAsync); asyncWorder.RunWorkerCompleted += new RunWorkerCompletedEventHandler(GetDataCompleted); frmProgress = new FrmProgress(); asyncWorder.RunWorkerAsync(new object[] { startDate, endDate }); frmProgress.StartPosition = FormStartPosition.CenterScreen; frmProgress.ShowDialog(this); frmProgress = null; }
private void GetDataCompleted(object sender, RunWorkerCompletedEventArgs e) { // The background process is complete. First we should hide the // modal Progress Form to unlock the UI. The we need to inspect our // response to see if an error occurred, a cancel was requested or // if we completed successfully. if (frmProgress != null) { frmProgress.Hide(); frmProgress = null; } // Check to see if an error occurred in the // background process. if (e.Error != null) { MessageBox.Show(e.Error.Message); return; } object[] fetchedCnts = (object[])e.Result; // Check to see if the background process was canceled. if (e.Cancelled) { MessageBox.Show(String.Format("操作取消!共更新 {0} 个订单,{1} 个消息", (int)fetchedCnts[0], (int)fetchedCnts[1]), "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); this.buttonSyncEbayData.Enabled = true; asyncWorder = null; return; } // Everything completed normally. // process the response using e.Result MessageBox.Show(String.Format("恭喜!下载ebay订单完成,共更新 {0} 个订单, 下载 {1} 个新消息 .", (int)fetchedCnts[0], (int)fetchedCnts[1]), "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); this.buttonSyncEbayData.Enabled = true; asyncWorder = null; LoadData(); isSyncingData = false; }