Performance problems counting the files with System.IO.Directory.GetFiles()

Viewed 3743

I use in a C# program

System.IO.Directory.GetFiles(dirname, "*.*", System.IO.SearchOption.AllDirectories).Length;

to count to number of files in a directory(and its subdirectories) on a share. I do this for many directories within a loop. The problem is now, that after 20-30 calls of GetFiles(...).Length my program is suddenly frozen or becomes very slow. What could be the reason for that and how can this problem be solved! Are there workarounds?

2 Answers
Related