2010-06-03 7 views
0

외부 앱에서 파일을 읽었습니다. 앱에서 이벤트를 가져 오기 위해 연결하고 싶습니다. 그러나 나는 ReadFile (또는 그 달성에 도움이 될 수있는 다른 것)을 연결하는 소스를 찾을 수 없습니다. 어떤 아이디어로 그렇게 할 수 있습니까? 사용자 모드에서 수행해야합니다. 나는 Process Monitor와 비슷한 것을 생각하고 있었다. 나는 그것이 어떻게되는지 궁금합니다.파일 읽기시 이벤트 발생?

답변

0

.net에서 FileSystemWatcher을 사용할 수 있습니다. 마지막 액세스 시간의 변경을 감지하는 Changed 이벤트에 대한 핸들러를 추가해야합니다 (다른 것들 중에서). 위의 링크 된 MSDN 예제에서

는 :

public static void Foo() 
{ 
    // Create a new FileSystemWatcher and set its properties. 
    FileSystemWatcher watcher = new FileSystemWatcher(); 
    watcher.Path = @"Your path"; 
    /* Watch for changes in LastAccess time */ 
    watcher.NotifyFilter = NotifyFilters.LastAccess; 
    // Only watch text files. 
    watcher.Filter = "*.txt"; 

    // Add event handlers. 
    watcher.Changed += new FileSystemEventHandler(OnChanged); 

    // Begin watching. 
    watcher.EnableRaisingEvents = true; 
} 

private static void OnChanged(object source, FileSystemEventArgs e) 
{ 
    // Specify what is done when a file is changed, created, or deleted. 
    Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType); 
} 
+0

이미 앱이 마지막 액세스 시간을 변경하지 않는 것을 시도했다. 그래서 그것은 그런 식으로 발견 될 수 없습니다. – blez

+0

읽기 파일을 잠급니까? –

+0

아니요, 그렇지 않습니다. – blez