Dispose() 호출이 중단 된 것처럼 보이는 FileSystemWatcher를 사용하여 이상한 문제가 발생하기 시작했습니다. 이것은 잠시 동안 아무런 문제없이 작업해온 코드이지만 .NET3.5 SP1로 업그레이드 했으므로 다른 사람이이 동작을 보았는지 확인하려고합니다.FileSystemWatcher 호출 중단 처리
이if (this.fileWatcher == null)
{
this.fileWatcher = new FileSystemWatcher();
}
this.fileWatcher.BeginInit();
this.fileWatcher.IncludeSubdirectories = true;
this.fileWatcher.Path = project.Directory;
this.fileWatcher.EnableRaisingEvents = true;
this.fileWatcher.NotifyFilter = NotifyFilters.Attributes;
this.fileWatcher.Changed += delegate(object s, FileSystemEventArgs args)
{
FileWatcherFileChanged(args);
};
this.fileWatcher.EndInit();
이 사용되는 방법은의 TreeNode 객체의 상태 이미지를 업데이트하는 것입니다
가 (비즈니스 관련 정보를 제거하기 위해 약간 조정) :
private void FileWatcherFileChanged(FileSystemEventArgs args)
{
if (this.TreeView != null)
{
if (this.TreeView.InvokeRequired)
{
FileWatcherFileChangedCallback d = new FileWatcherFileChangedCallback(FileWatcherFileChanged);
this.TreeView.Invoke(d, new object[]
{
args
});
}
else
{
switch (args.ChangeType)
{
case WatcherChangeTypes.Changed:
if (String.CompareOrdinal(this.project.FullName, args.FullPath) == 0)
{
this.StateImageKey = GetStateImageKey();
}
else
{
projectItemTreeNode.StateImageKey = GetStateImageKey();
}
break;
}
}
}
}
인가 여기은 FileSystemWatcher를 생성하는 코드는 우리가 누락되었거나 .NET3.5 SP1에서이 이상한 것이 있습니까?
FileSystemWatcher를 사용하는 경우 다른 스레드를 사용할 가능성이 있습니다. FileSystemWatcher 스레드가 UI 스레드에서 호출을 시도 할 때 차단 될 수 있습니다. –