解决C#中FileSystemWatcher类的Changed事件触发多次的问题。
2013-06-27 14:30
791 查看
fsw = new FileSystemWatcher(System.Environment.CurrentDirectory + "\\conf\\","*.xml");
fsw.EnableRaisingEvents = true;
fsw.NotifyFilter = NotifyFilters.LastWrite;
fsw.Changed += new FileSystemEventHandler(fsw_Changed);
首先设置NotifyFilter为LastWrite,这个就屏蔽了因为杀毒软件等各种外部因素导致Changed事件被触发。
然后设置它的EnableRaisingEvents属性如下:
C#代码
private void fsw_Changed(object sender,EventArgs e)
{
fsw.EnableRaisingEvents = false;
LoadTreeViewData();
fsw.EnableRaisingEvents = true;
}
这样,先设置为false然后处理完文件之后再设置为true即可。
fsw.EnableRaisingEvents = true;
fsw.NotifyFilter = NotifyFilters.LastWrite;
fsw.Changed += new FileSystemEventHandler(fsw_Changed);
首先设置NotifyFilter为LastWrite,这个就屏蔽了因为杀毒软件等各种外部因素导致Changed事件被触发。
然后设置它的EnableRaisingEvents属性如下:
C#代码
private void fsw_Changed(object sender,EventArgs e)
{
fsw.EnableRaisingEvents = false;
LoadTreeViewData();
fsw.EnableRaisingEvents = true;
}
这样,先设置为false然后处理完文件之后再设置为true即可。
相关文章推荐
- jquery mobile的触控点击事件会多次触发问题的解决方法
- jquery mobile的触控点击事件会多次触发问题的解决方法
- 解决WebBrowser多次触发LoadCompleted事件的问题
- js onmousewheel事件多次触发问题解决方法
- js onmousewheel事件多次触发问题解决方法
- C# 之 FileSystemWatcher事件多次触发的解决方法
- js onmousewheel事件多次触发问题的解决
- js函数节流 函数去抖来解决多次触发事件的问题
- unbind方法在事件中的使用,解决同类或同名元素事件触发多次问题
- 未解决的问题_c#中,最小化触发事件
- 解决jQuery ajax动态新增节点无法触发点击事件的问题
- 定时自动同步文件,支持多文件夹同步,支持过滤文件和文件夹,解决FileSystemWatcher多次文件触发事件(源码)
- 输入时触发事件,解决中文输入时的触发问题
- C# 通过事件触发UI的问题
- HTML5异步上传图片(支持预览和进度条),使用其他按钮触发file onclick事件,解决某些浏览器无法触发的问题
- 解决IE 下div与img重叠无法触发鼠标事件的问题
- 解决事件多次绑定,执行多次问题
- vue—webapp 解决点击遮罩层会触发界面上其他元素的click事件问题
- C# 注销掉事件,解决多播委托链表的问题
- Dev GridControl修改单元格无法触发CellValueChanged事件的解决方法