سؤال

This is my code:

 _instrumentsFolderWatcher.Changed += _instrumentsFolderWatcher_Changed;
 _instrumentsFolderWatcher.Created += _instrumentsFolderWatcher_Created;
 _instrumentsFolderWatcher.Deleted += _instrumentsFolderWatcher_Deleted;

where _instrumentsFolderWatcher is instance of FileSystemWatcher. Problem is when I paste a file in the folder which is being monitored, both the created and changed events are fired. Why would changed event be fired? Further the changed event is fired with ChangeType of Changed. How do I get around this issue?

Edit: Why is Changed event not fired when I change the filename?

هل كانت مفيدة؟

المحلول

MSDN FileSystemWatcher Class

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. Likewise, some applications (for example, antivirus software) might cause additional file system events that are detected by FileSystemWatcher.

Try using the Renamed event to determine when a file is renamed.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top