private void bgwImportar_DoWork(object sender, DoWorkEventArgs e) { Cursor.Current = Cursors.WaitCursor; foreach (DataGridViewRow row in grdImportacao.Rows) { Console.WriteLine(row.Cells["Rotina"].Value.ToString() + " em row:" + row.Index.ToString()); cImportar.ProcessarImportacao(row.Cells["Rotina"].Value.ToString(), row.Index); } }
private void bgwImportar_DoWork(object sender, DoWorkEventArgs e) { try { Cursor.Current = Cursors.WaitCursor; foreach (DataGridViewRow row in grdImportacao.Rows) { //row.Cells["Status"].Value = "..."; Console.WriteLine(row.Cells["Rotina"].Value.ToString() + " em row:" + row.Index.ToString()); Task vResult = cImportar.ProcessarImportacao(row.Cells["Rotina"].Value.ToString(), row.Index); if (vResult == null) { row.Cells["Status"].Value = "Erro"; row.DefaultCellStyle.ForeColor = Color.Red; } else { row.Cells["Status"].Value = "Importado"; row.DefaultCellStyle.ForeColor = Color.Green; } } } catch (Exception vE) { if (vE.Message == "Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.") { //erro conhecido - ignorado Trace.WriteLine(DateTime.Now.ToString() + "FormDeposito.bgwImportar_DoWork()"); Trace.TraceError(vE.Message); } else { Trace.WriteLine(DateTime.Now.ToString() + "FormDeposito.bgwImportar_DoWork()"); Trace.TraceError(vE.Message); MessageBox.Show(vE.Message, vE.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }