Windows 2003에서 Windows 서비스를 실행하고 있습니다. 지난 달 동안 매일 코드를 추가/변경했는데 파일 워처가 지난 달 동안 매일 작동했습니다. 그러나, 그것은 이상한 이유로 오늘 일하는 것을 멈췄습니다. 이전 코드로 되 돌리면 여전히 이벤트가 발생하지 않습니다. Win7 머신에서 동일한 코드를 테스트했는데 정상적으로 작동합니다. 나는 외부 프로세스가 간섭한다고 가정하고 있지만 무엇을 찾을 지조차 확신하지 못합니다. 디버그 문을 통해Windows 서비스의 FileWatcher가 갑자기 작동하지 않습니다.
private void InitializeComponent()
{
this.processfileWatcher = new System.IO.FileSystemWatcher();
((System.ComponentModel.ISupportInitialize) (this.processfileWatcher)).BeginInit();
this.processfileWatcher.EnableRaisingEvents = true;
this.processfileWatcher.Filter = "done.txt";
this.processfileWatcher.Changed += new System.IO.FileSystemEventHandler(this.processfileWatcher_Changed);
this.ServiceName = "Service1";
((System.ComponentModel.ISupportInitialize)(this.processfileWatcher)).EndInit();
}
private void processfileWatcher_Changed(object sender, System.IO.FileSystemEventArgs e)
{
try
{
processfileWatcher.EnableRaisingEvents = false;
//Do stuff here
Debug.WriteLine(" End of processfileWatcher for: " + e.FullPath);
}
finally
{
processfileWatcher.EnableRaisingEvents = true;
}
}
내가 내 ONSTART() 메소드의 끝에 도달하고 있음을 확인 할 수 있습니다
여기에 관련 코드입니다.
어디 당신은 FileSystemWatcher의 경로 속성을 설정하는? –
/onstart/onstop 메서드가있는 클래스의 생성자에서 public Ex() { Settings = new Settings(); InitializeComponent(); processfileWatcher.Path = Settings.ProcessFolder; } – user1287523
내가 왜 당신에게 효과가 있는지 모르겠지만 몇 가지 일반적인 코드 제안 사항이 있습니다 : 1)'FileSystemWatcher'를'FileSystemWatcher'로 형변환 할 필요가 없습니다. 2) Init 코드 안에 Path 필드를 설정하는 것이 좋습니다. –