I need some help. Right now i have done a file search that will search my entire hard drive and it works. Here are the two methods that does it.
public void SearchFileRecursiveNonMultithreaded()
{
//Search files multiple drive
string[] drives = Environment.GetLogicalDrives();
foreach (string drive in drives)
{
if (GetDriveType(drive).ToString().CompareTo("DRIVE_FIXED") == 0)
{
DriveInfo driveInfo = new DriveInfo(drive);
if (driveInfo.IsReady)
{
System.IO.DirectoryInfo rootDirectory = driveInfo.RootDirectory;
RecursiveFileSearch(rootDirectory);
}
}
}
MessageBox.Show(files.Count.ToString());
}
public void RecursiveFileSearch(DirectoryInfo root)
{
DirectoryInfo[] subDirectory;
try
{
//private List<FileInfo> files = new List<FileInfo>() is declared above
files.AddRange(root.GetFiles(searchString.Text, SearchOption.TopDirectoryOnly));
}
catch (Exception)
{
}
try
{
// Now find all the subdirectories under this directory.
subDirectory = root.GetDirectories();
foreach (System.IO.DirectoryInfo dirInfo in subDirectory)
{
// Resursive call will be performed for each subdirectory.
RecursiveFileSearch(dirInfo);
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
Right now i am trying to implement a parallel search to make the search faster. I tried several procedures to get this to work. Tried to use backgroundworker as well as threads but have problems with it and it is very difficult to debug to know what is wrong ? Can someone let me know the approach to implement a parrallel search. The step will do i will go and figure out on my own. Any help provided will be greatly apperciated.