I have a FileSystemWatcher
listening on a folder. When I try renaming this folder (in Windows Explorer) I get a
The action can't be completed because the folder or a file in it is open in another program
error.
Commenting out the FileSystemWatcher
calls fixes this.
I've tried reproducing the error with a simple program, but haven't been successful so I'm not sure what's going on here. Has anyone encountered anything like this with a FileSystemWatcher
? If so - what might be causing it?
More information:
The following seems to be enough to cause the error:
FileSystemWatcher fsw = new FileSystemWatcher(path);
fsw.Deleted += new FileSystemEventHandler(fsw_Deleted);
fsw.EnableRaisingEvents = true;
I can rename files in that folder. And sibling files. I even tried putting a return;
as the first line in fsw_Deleted
. Still didn't work. As didn't closing Visual Studio, and deleting obj and bin, and running again. And I even tried running the exe file not within VS. Still - no lock if it's not running, Locked if it is.
I've discovered what caused this. There was a second FileSystemWatcher
- on a sub directory of the first - which didn't allow renaming the first.
(I'm still surprised, though. A FileSystemWatcher
should be "invisible".)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With