How do I detect when a directory or file changes without constant scanning
问题 Other than reading all the files and comparing them with a previous snapshot, is there a way to detect when a directory changes in C# with Windows? I don't mind PInvoke if that's what it takes. EDIT The FileSystemWatcher class is great, but one gotcha is that you must kick off any work in the callback notification to a background task/thread to avoid blocking which will cause dropped events. 回答1: Use the FileSystemWatcher class - it does what you want. It won't tell you which bytes in the