FileSystemWatcher的 - 只有改变事件一次射击一次? [英] FileSystemWatcher - only the change event once firing once?

查看:177
本文介绍了FileSystemWatcher的 - 只有改变事件一次射击一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code监听文件我下载关闭服务器和开放的变化事件。但是改变事件只被炒鱿鱼的第一次保存文件,然后在随后的保存文件观察者不火的更改事件?

I'm using the below code to listen for change events of a file i download off a server and open. however the change event only gets fired the first time the file is saved, then on subsequent saves the file watcher does not fire the change events?

任何人都可以看到最新回事?

Can anyone see whats going on?

private FileSystemWatcher StartWatchingFile()
{
	fw = new FileSystemWatcher();
	fw.Path = this.directoryLocation;
	fw.Filter = this.Filename;

	fw.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite;

	// Add event handler
	fw.Changed += new FileSystemEventHandler(fw_Changed);

	// Open file		
System.Diagnostics.Process.Start(this.CreateAbsoluteFilePath(this.Filename));

	// Begin watching.
	fw.EnableRaisingEvents = true;

	return fw;
}

//************************	

	void fw_Changed(object sender, FileSystemEventArgs e)
	{
		MessageBox.Show("File: " + e.FullPath + " " + e.ChangeType);
    }

编辑:StartWatchingFile()现在返回其保存在不会被垃圾收集类的filewatcher,只是为了确保我抱着全班同学为认为fw_changed()函数可能无法被调用。于是全班现在没有得到垃圾collectioned。这个类是在一个ArrayList的是一个类的公共成员持有

The StartWatchingFile() now returns the filewatcher which is kept in a class that will not be garbage collected, just to make sure i'm holding the whole class as thought the fw_changed() function might not be able to be called. So the whole class is now not getting garbage collectioned. The class is held in a ArrayList which is a public member of a class

问候,

乔恩

推荐答案

我很抱歉,我不能回答你的问题具体。在一般情况下,我会做出贡献的是,如果你使用它的话,你就会知道FileSystemWatcher的是不可靠的。微软连接显示多个问题的吧。我同意<一个href="http://stackoverflow.com/questions/239988/filesystemwatcher-vs-polling-to-watch-for-changes/240008#240008">Jason杰克逊的采取上FileSystemWatcher的。

I'm sorry I can't answer your question specifically. In general, I'll contribute that, if you use it enough, you'll learn that FileSystemWatcher is not reliable. Microsoft Connect shows multiple problems with it. I agree with Jason Jackson's take on FileSystemWatcher.

这篇关于FileSystemWatcher的 - 只有改变事件一次射击一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆