How can I get an information about the ejection request, so that my app can remove the FileSystemWatcher for that drive and doesn't block this operation?
USB drive ejection blocked

The user can plug in any folder from any drive into my app, so also from USB drives. The app is then watching the folders changes by using FileSystemWatcher
. But if the user wants to eject the drive by clicking the icon in the task notification area, it cannot be removed because obviously the FileSystemWatcher
keeps this drive in usage. If I use Spy++, I connot see that my app gets any windows message which could inform my MainWindow
that a ejection is requested. How can I get an information about the ejection request, so that my app can remove the FileSystemWatcher
for that drive and doesn't block this operation?
-
Castorix31 68,306 Reputation points
2023-03-05T17:57:57.6066667+00:00
It is DBT_DEVICEQUERYREMOVE
(tested on Windows 10 22H2 with RegisterDeviceNotification and DBT_DEVTYP_HANDLE)
Yes, I will try it.