Skip to main content
added 140 characters in body
Source Link
Adriano Repetti
  • 10.5k
  • 1
  • 23
  • 47

100 I/O parallel operations might be too much, you will find a balance only with real-world testing but a reasonable value may be around 4 (especially because each operation is very short and threading overhead may be too high). Not to mention that hardly .NET scheduler will really start so many threads for your loop then probably you will not note any difference.

100 I/O parallel operations might be too much, you will find a balance only with real-world testing but a reasonable value may be around 4 (especially because each operation is very short and threading overhead may be too high).

100 I/O parallel operations might be too much, you will find a balance only with real-world testing but a reasonable value may be around 4 (especially because each operation is very short and threading overhead may be too high). Not to mention that hardly .NET scheduler will really start so many threads for your loop then probably you will not note any difference.

added 75 characters in body
Source Link
Adriano Repetti
  • 10.5k
  • 1
  • 23
  • 47

That's all, note that you can pass function directly without wrapping inside (another) anonymous delegate. SearchOption.AllDirectories already search inside all sub-directories. If you do not have circular hard-links then it's way faster than your recursive implementation. If you need it to handle fine granted access permissions then code will be much more complex than this and you should definitely catch relevant exceptions (Directory.EnumerateFiles() will easily let you handle this problems case-by-case, see this SO post).

That's all, note that you can pass function directly without wrapping inside (another) anonymous delegate. SearchOption.AllDirectories already search inside all sub-directories. If you do not have circular hard-links then it's way faster than your recursive implementation. If you need it to handle fine granted access permissions then code will be much more complex than this and you should definitely catch relevant exceptions (Directory.EnumerateFiles() will easily let you handle this problems case-by-case).

That's all, note that you can pass function directly without wrapping inside (another) anonymous delegate. SearchOption.AllDirectories already search inside all sub-directories. If you do not have circular hard-links then it's way faster than your recursive implementation. If you need it to handle fine granted access permissions then code will be much more complex than this and you should definitely catch relevant exceptions (Directory.EnumerateFiles() will easily let you handle this problems case-by-case, see this SO post).

added 490 characters in body
Source Link
Adriano Repetti
  • 10.5k
  • 1
  • 23
  • 47

Note that a null argument and and empty argument are different (eventually path may even be empty to use current directory) and as such they should handled separately. First test is to throw ArgumentNullException instead of a generic ArgumentException if path is null. Second test may be rewritten to path.Length == 0 but I find IsNullOrEmpty() much more explicative then I accept the price of the redundant null-checking (at least until I'll need IsNullOrWhiteSpace()).

We're now at the core of your function. First of all drop ToList() because you do not need it.

We're now at the core of your function. First of all drop ToList() because you do not need it.

Note that a null argument and and empty argument are different (eventually path may even be empty to use current directory) and as such they should handled separately. First test is to throw ArgumentNullException instead of a generic ArgumentException if path is null. Second test may be rewritten to path.Length == 0 but I find IsNullOrEmpty() much more explicative then I accept the price of the redundant null-checking (at least until I'll need IsNullOrWhiteSpace()).

We're now at the core of your function. First of all drop ToList() because you do not need it.

added 170 characters in body
Source Link
Adriano Repetti
  • 10.5k
  • 1
  • 23
  • 47
Loading
Source Link
Adriano Repetti
  • 10.5k
  • 1
  • 23
  • 47
Loading