I have a winform
application to search for a certain text within a file path.
The problem is that it takes a lot in some searches and in Sometimes it falls. It would be convenient if someone can help me improve the performance of it, I share the code:
private void btnexplorador_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
txtruta.Text = fbd.SelectedPath;
}
}
private void btnbuscar_Click(object sender, EventArgs e)
{
lbxlista.Items.Clear();
string ruta = @"" + txtruta.Text; //Escribir ruta
string texto = txtfiltro.Text; //Escribir texto a buscar
string[] files = Directory.GetFiles(ruta, "*", SearchOption.AllDirectories);
//List<string> encontrados = new List<string>();
foreach (string item in files)
{
string contenido = File.ReadAllText(item);
if (contenido.Contains(texto))
lbxlista.Items.Add(item);
}
}