void BGW_DoWork(object sender, DoWorkEventArgs e) { LastObj _app = (LastObj)e.Argument; _app.message = tool.CheckAccount("" + _app.row.Cells[SchoolDomain.Index].Value); e.Result = _app; }
private void Connet(DataGridViewRow row) { LastObj _app = new LastObj(); _app.row = row; _app.row.Cells[ColStatus.Index].Value = "連線中,請稍後..."; BackgroundWorker BGW = new BackgroundWorker(); BGW.DoWork += BGW_DoWork; BGW.RunWorkerCompleted += BGW_RunWorkerCompleted; BGW.RunWorkerAsync(_app); }
void BGW_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { LastObj _app = (LastObj)e.Result; if (!e.Cancelled) { if (e.Error == null) { _app.row.Cells[ColStatus.Index].Value = _app.message; } else { _app.row.Cells[ColStatus.Index].Value = "失敗:其它:" + e.Error.Message; } } else { _app.row.Cells[ColStatus.Index].Value = "失敗:其它:已取消連線"; } }