Closed Yomodo closed 6 years ago
Pardon my ignorance in case this question is silly, but how would this play out with .net existing error handling methodologies? Specifically parallel.foreach when run from a task factory does not allow for exception handling in there without dying a horrible messy convoluted death when enumerating 100 000's of folders and millions of files in parallel. Currently I am running into these errors in a await Task.Factory.StartNew(() => Parallel.ForEach(rootFolders, (currentFolder) => { try { //do something with Alphaleonis.Win32.Filesystem.DirectoryInfo.GetDirectories(); //that causes exception (mambo) #5 like try to access recycle bin, volume info etc } catch (Exception ex) { ExceptionQ.Enqueue(ex); } })); When queuing up errors in a ConcurrentQueue I can just handle them in a managed way single thread in the caller after all is done.
The AlphaFS .NET implementations will remain as-is.
I haven't tried the DirectoryEnumerationFilters yet in a parallel context, so I'm not sure how that will turn out. For "normal" processing, these filters work well.
Enumerating folders/files can raise error 5: Access Denied Exceptions.
Using DirectoryEnumerationFilters enumerating can report these exceptions and continue.
Added bonus is additional folder/file criteria filtering: Example/Unit Test