I have the following piece of code that searches a directory for a file containing a specific order number and return the full path. Depending on the directory it searches it can take some time so I like to run this using the BackgroundWorker but I am not sure how to pass the resulth (full path) back so I can use it on my next method.
Currently I am setthing a string variable _FilePath with the result (full path) and using it on the next method to load the file into a rich text box
If anyone can help mme get the information back from the BackGroundWorker it would be much appreciated
Thanks
RJL
Right now I do not have anything on the backgroundWorker1_DoWork or backgroundWorker1_RunWorkerCompleted
Currently I am setthing a string variable _FilePath with the result (full path) and using it on the next method to load the file into a rich text box
If anyone can help mme get the information back from the BackGroundWorker it would be much appreciated
Thanks
RJL
Right now I do not have anything on the backgroundWorker1_DoWork or backgroundWorker1_RunWorkerCompleted
Code:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
}
private void FindInFiles(string directoryArg, string containsTextArg, bool ignoreCaseArg, params string[] fileWildcardsArg)
{
// This List accumulates files found.
List<String> files = new List<string>();
foreach (string fileWildcard in fileWildcardsArg)
{
string[] xFiles = System.IO.Directory.GetFiles(directoryArg, fileWildcard);
foreach (string x in xFiles)
{
// If file not already found...
if (!files.Contains(x))
{
bool containsText =
containsTextArg.Length == 0 ||
ignoreCaseArg ?
System.IO.File.ReadAllText(x).ToLower().Contains(containsTextArg.ToLower()) :
System.IO.File.ReadAllText(x).Contains(containsTextArg);
if (containsText)
{
// This file is a keeper. Add it to the list. and set is as a varialbe
[highlight #FCE94F]_FilePath = x;[/highlight]
}
}
}
}
LoadFile();
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
}