2017-03-24 3 views
2

FileSystemWatcher을 만들 때 볼 수있는 NotifyFilters을 선택할 수있는 옵션이 있습니다. 그러나 내 이해를 위해 또는 NotifyFilters.Attributes과 같이 FileSystemWatcher.Changed 이벤트를 트리거 할 수있는 복수 NotifyFilters이 있습니다.어떤 NotifyFilter가 FileSystemWatcher.Changed를 트리거 했습니까?

코드 :

FileSystemWatcher watcher = new FileSystemWatcher(); 
watcher.Path = Path.GetDirectoryName(PATH); 
watcher.Filter = Path.GetFileName(PATH); 
watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size | NotifyFilters.FileName | NotifyFilters.Security | 
         NotifyFilters.CreationTime | NotifyFilters.Attributes | NotifyFilters.LastAccess | NotifyFilters.DirectoryName; 
watcher.Changed += OnFileSystemWatcher_Changed; 
watcher.Deleted += OnFileSystemWatcher_Deleted; 
watcher.Created += OnFileSystemWatcher_Created; 
watcher.Renamed += OnFileSystemWatcher_Renamed; 

private void OnFileSystemWatcher_Changed(object sender, FileSystemEventArgs e) 
{ 
    // Do Stuff 
} 

문제 : FileSystemWatcher.Changed 이벤트에 대한 내 이벤트 처리기에서, 이벤트를 발생하는 NotifyFilter 결정하는 방법이?

시도 : 난 그냥 NotifyFilter의 각 유형에 대한 새로운 FileSystemWatcher을 만드는 방법에 대해 생각했다,하지만 메모리의 매우 효율적인 사용은 아닌 것 같아. 나는 더 깨끗한 방법이 있기를 바랬습니다.

답변

2

아니요, FileSystemWatcher에 의해 호출되는 기본 Windows API가 이러한 정보를 제공하지 않기 때문에이 방법을 찾을 방법이 없습니다. 라고 API는 ReadDirectoryChangesW이며 다음 필드가 FILE_NOTIFY_INFORMATION 구조에서 결과를 반환 조치가 생성됩니다

typedef struct _FILE_NOTIFY_INFORMATION { 
    DWORD NextEntryOffset; 
    DWORD Action; 
    DWORD FileNameLength; 
    WCHAR FileName[1]; 
} FILE_NOTIFY_INFORMATION, *PFILE_NOTIFY_INFORMATION; 

는 \ 수정 \ 이름을 변경 \ 삭제. 보시다시피, 어떤 필터가 변경을 유발했는지에 대한 정보가 없습니다.