我通過使用從Stackoverflow獲得的代碼得到了它的工作原理!
// Takes same patterns, and executes in parallel
public static IEnumerable<string> GetDirs(string path, string searchPattern, SearchOption searchOption = SearchOption.TopDirectoryOnly)
{
return Directory.EnumerateDirectories(path, searchPattern, searchOption);
}
// Takes same patterns, and executes in parallel
public static IEnumerable<string> GetFiles(string[] paths,string searchPattern, SearchOption searchOption = SearchOption.AllDirectories)
{
return paths.AsParallel().SelectMany(path => Directory.EnumerateFiles(path, searchPattern, searchOption));
}