In the question I asked Retrieve a list of filenames in folder and all subfolders quickly And a few others I have found, it seems the way to search many files is to use the EnumerateFiles Method.
The EnumerateFiles and GetFiles methods differ as follows: When you use EnumerateFiles, you can start enumerating the collection of names before the whole collection is returned; when you use GetFiles, you must wait for the whole array of names to be returned before you can access the array. Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.
This sounds Great for me, my search is taking about 10 seconds, so I can start makign my list as the information comes in. But I can't figure it out. When I run the EnumerateFiles Method, the application freezes until it completes. I could run it in a background worker, but the same thing will happen to that thread. Any help?
DirectoryInfo dir = new DirectoryInfo(MainFolder);
List<FileInfo> matches = new List<FileInfo>(dir.EnumerateFiles("*.docx",SearchOption.AllDirectories));
//This wont fire until after the entire collection is complete
DoSoemthingWhileWaiting();