I have a Windows service written in C # with the .NET 2.0 platform that uses FileSystemWatcher to monitor specific directories for changes. Some of these directories may be on removable media, such as a USB drive. When a new disk is connected to the system, I receive a notification through a WMI request and can configure a new FileSystemWatcher. It all works well.
The difficulty is that I want the user to be able to eject the disk using the Windows Safe Hardware Removal application, but Windows reports that the disk is busy because I am tracking it through FileSystemWatcher and tells the user that the disk cannot be deleted.
So my question is, how can my Windows service know when a user requests a surge so that I can remove the file system monitor and allow the request to succeed?
source share