I have some code below that goes through all the directories of a given area sDir
it also runs on it's own thread. This builds a liststring that then gets converted to an array to build a treeview.
However I would also like to count the number of directories and files that the search is up to and display it on my UI. If i add the this.Invoke((MethodInvoker)(() => DirCL.Text = "Dir: " + dirC.ToString()));
and the this.Invoke((MethodInvoker)(() => FileCL.Text = "Files: " + FileC.ToString()));
liststring.Add(Files);
This makes the function go from 10 seconds to do an area with 65,000 files to 100ish seconds.
I assume this Increase is because the MethodInvoker is pausing the function to go write to the UI.
Is there a better way for me to be writing code to the UI that is in a different thread?
int dirC = 0;
int FileC = 0;
private void DirSearch(string sDir)
{
try
{
string[] array1 = Directory.GetDirectories(sDir);
for (int i1 = 0; i1 < array1.Length; i1++)
{
string Dir = array1[i1];
dirC++;
//this.Invoke((MethodInvoker)(() => DirCL.Text = "Dir: " + dirC.ToString()));
try
{
String[] array = Directory.GetFiles(Dir, txtFile.Text);
for (int i = 0; i < array.Length; i++)
{
string Files = array[i];
FileC++;
//this.Invoke((MethodInvoker)(() => FileCL.Text = "Files: " + FileC.ToString()));
liststring.Add(Files);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}
DirSearch(Dir);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
ErrC++;
}
}