This is terribly flabby, but in the past I ran into this problem by creating my own decorator for the FileSystemWatcher class. Inside, it creates a FileSystemWatcher and logs the "Created and Modified" events, wraps them and displays its own created and modified events after the files are finished, similar to this:
private void Watcher_Changed(Object sender, FileSystemEVentArgs e) { while (true) { FileStream stream; try { stream = File.Open(e.FullPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None); // If this succeeds, the file is finished Changed(); } catch (IOException) { } finally { if (stream != null) stream.Close(); } } }
Some of them are taken from the answer here . In fact, you should not use an infinite loop. You probably want to add timeouts, sleep between checks, etc., but this is a general idea.
source share