I have created an application that allows me to validate the existence of images with any type of extension using the numero_guia(GUIA001__789656.tif)
as a pattern.
Currently my app works without problems, but I would like to improve it.
I will explain a little, what I do here is to obtain guide numbers from the database and compare them in a path of images string[] archivos = Directory.GetFiles(ruta, nom_imagen_db + ".*");
.
Is it possible to save all the image names of a folder in a array
and perform the comparison within my foreach
? and thus prevent you from consulting the image folder that is hosted on a server, and speed up the process.
Currently a list of 550000 records takes 1 hour and 40 minutes. With this, would you accelerate the validation process? I hope you can help me. Thanks.
try
{
BackgroundWorker worker = sender as BackgroundWorker;
//INICIO FOR
int i = 0;
foreach (DataRow row in dtImagenes.Rows)
{
if (!worker.CancellationPending)
{
string nom_imagen_db = row["NroGuia"].ToString().TrimEnd(' ');
string[] archivos = Directory.GetFiles(ruta, nom_imagen_db + ".*");
string[] archivos2 = Directory.GetFiles(ruta, nom_imagen_db + "_*");
if (archivos.Length == 0 && archivos2.Length == 0)
{
string f_guia = row["FechaGuia"].ToString();
guias.InsertarGuiasValidadas(nom_imagen_db,
Convert.ToDateTime(f_guia), DateTime.Now, "NO");
cantidad_guias_sin_img++;
nro_guia_correo = nro_guia_correo + "<br />" + nom_imagen_db;
}
else
{
cantidad_guias_con_img++;
}
worker.ReportProgress(i++);
}
else
{
e.Cancel = true;
break;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}