I am using the BackgroundWorker component to generate a task in the background, what I do is traverse a datatable and execute a search in a second datatable to verify if the data to compare exists, if so, then execute a store procedure.
The problem I have is that when making the query in the datatable using linq leaves the backgroundWorker and does not perform the task, I want to know how to correct this situation.
Archivo archivo = new Archivo();
dta = (DataTable)dgvRegistros.DataSource;
dta1 = (DataTable)dgvProcesado.DataSource;
int progreso = 0;
foreach (DataRow row in dta.Rows)
{
var dato = dta1.AsEnumerable().Where(c => c.Field<string>("Referencia") == row["Transaccion"].ToString()).FirstOrDefault();
if (dato == null)
{
archivo.GuardarDeposito(idcuenta, row["Descripcion"].ToString(), double.Parse(row["Monto"].ToString()),
row["Referencia"].ToString());
}
progreso++;
backgroundWorker3.ReportProgress(progreso);
}