Filesystem watcher and large files

Solution found on stackoverflow and modified it a bit. static bool IsFileLocked(FileInfo file) { FileStream stream = null; try { stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None); } catch (IOException) { //the file is unavailable because it is: //still being written to //or being processed by another thread //or does not exist (has already been processed) return … Read more

How reliable is the FileSystemWatcher in .netFramwork 4?

FileSystemWatcher relies on underlying file system support, so any reliability issues with the file system will be visible as reliability issues with FileSystemWatcher. For example, if you are watching a network directory, then the network server’s reliability will affect FileSystemWatcher‘s reliability. For example, the server may crash and be restarted. You will not be notified … Read more

System.IO.FileSystemWatcher to monitor a network-server folder – Performance considerations

From a server load point of view, using the IO.FileSystemWatcher for remote change notifications in the scenario you describe is probably the most efficient method possible. It uses the FindFirstChangeNotification and ReadDirectoryChangesW Win32 API functions internally, which in turn communicate with the network redirector in an optimized way (assuming standard Windows networking: if a third-party … Read more

How to monitor a complete directory tree for changes in Linux?

I’ve done something similar using the inotifywait tool: #!/bin/bash while true; do inotifywait -e modify,create,delete -r /path/to/your/dir && \ <some command to execute when a file event is recorded> done This will setup recursive directory watches on the entire tree and allow you to execute a command when something changes. If you just want to … Read more

Detecting moved files using FileSystemWatcher

According to the docs: Common file system operations might raise more than one event. For example, when a file is moved from one directory to another, several OnChanged and some OnCreated and OnDeleted events might be raised. Moving a file is a complex operation that consists of multiple simple operations, therefore raising multiple events. So … Read more

FileSystemWatcher to watch UNC path

I just tried this: var _watcher = new FileSystemWatcher(); _watcher.Path = @”\\10.31.2.221\shared\”; _watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName; _watcher.Filter = “*.txt”; _watcher.Created += new FileSystemEventHandler((x, y) =>Console.WriteLine(“Created”)); _watcher.Error += new ErrorEventHandler( (x, y) =>Console.WriteLine(“Error”)); _watcher.EnableRaisingEvents = true; Console.ReadKey(); That works without problems, however i replicated your exception just when: The running user doesn’t have permissions to … Read more