본문 바로가기

software

.net 파일 감시

 File System Watcher class

control에서 CrossThread에 의한 Side effect를 줄이고자 할 경우 다음과 같이 사용할 수 있다.


 

  1. CheckForIllegalCrossThreadCalls = false;
  2. FileSystemWatcher w = new FileSystemWatcher();
  3.  
  4. //w.Path =  path string
  5.  
  6. w.NotifyFilter = NotifyFilters.LastAccess| NotifyFilters.LastWrite
  7.                  |NotifyFilters.FileName|NotifyFilters.DirectoryName;
  8. w.Filter = "*.jpeg";
  9.  
  10. w.Changed += new FileSystemEventHandler(OnChanged);
  11. w.Created += new FileSystemEventHandler(OnChanged);
    w.Deleted += new FileSystemEventHandler(OnChanged);
    w.Renamed += new RenamedEventHandler(OnRenamed);
  12. // Begin watching.
    watcher.EnableRaisingEvents = true;

    // Wait for the user to quit the program.
    Console.WriteLine("Press \'q\' to quit the sample.");
    while(Console.Read()!='q');

이 글은 스프링노트에서 작성되었습니다.

'software' 카테고리의 다른 글

부사수의 코드 2탄  (0) 2012.12.18
내 부사수의 안타까운 코드  (0) 2012.12.18
Facebook tableview cell  수정위치  (0) 2010.10.26
exif read library  (0) 2009.08.04
image metadata  (0) 2009.08.03