I have a function fire every 2 minutes from a Threading.Timer. The function goes through a directory (hardcoded in) and deletes all .ev1 files in it. This directory is on a server and has a file moved to it every ~2 minutes.
It worked for about a day or so, the directory was empty, or had 1 file in it. Now I went to check it and there’s 746 files in it. I put a breakpoint after this line:
String[] Files = System.IO.Directory.GetFiles(MachineDir, WatcherFileType, SearchOption.AllDirectories);
Where MachineDir is the directory I’m looking at (I double checked that the directory string is correct). WatcherFileType is .ev1.
Is there some bug with Directory.GetFiles? or possibly something with running this app for extended periods of time.
Have you tried setting WatcherFileType to “*.ev1”
Also you might want to look into the FileSystemWatcher object which doesn’t use polling:
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx