I guess the next step is re-implementing the native watcher with more fine grained control. Being able to differentiate between directories and files has some performance benefits at logic level, as we can dispatch various handlers based on the notification kind (file/directory).Ī quick workaround was to create 2 filesystemwatchers, one which monitors files, one which monitors directories and handle them differently. In VSMac, we have a global file system watcher over the projects, and we are receiving events for IO being done. Not sure there is a solution given cross-platform constraints, as Windows does not have an easy way to query this information. Or anything that already exists? enum NotificationKindĪnd that value would be File/Directory on Win10+, and Unknown on older OS. / /// Gets whether the notification was for a file or a directory, based on /// public NotificationKind Kind I feel like a dirty hack that would suffice:
#Filewatcher notifyfilters code#
This line of code is telling the FileSystemWatcher to only watch for changes. But that requires bumping the minimum OS requirement to get FileAttributes access and increasing the overhead of information passed by the OS, decreasing the buffer element capacity. fileSystemWatcher.NotifyFilter NotifyFilters.FileName NotifyFilters.Size. I would be happy if we could at least provide whether the changed item is a file or a directory. Linux: inotify has the required info End note MacOS: FSEventStream has the required flags passed over on the callback. I guess there is no real solution for Windows as-is, with the current native APIs.
Another concern would be having fewer events buffered (larger buffer struct size). If it reports actual values, then this API is not helpful at all, because the watcher would have to keep track of the file metadata internally to be able to report deltas - again, a no-go. netcore going to run on Windows 10+ only? ? ReadDirector圜hangesExW has file information, but I'm unsure whether this just reports changed values based on the notify filter or all the values - not all the docs mention that.
I worked on a nice little idea with a colleague, Ross Sandford, utilising Memor圜ache as a buffer to ‘throttle’ additional events.
#Filewatcher notifyfilters how to#
Interesting, did not know that detail about the windows side of things, should've done better initial research. Good use of NotifyFilters (see my post on how to select NotifyFilters) can help but there are still plenty of scenarios, like those above, where additional events will still get through for a file system event.