FileSystemWatcher的更改不会触发事件 [英] FileSystemWatcher Changed event doesn't fire

查看:518
本文介绍了FileSystemWatcher的更改不会触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FileSystemWatcher fsw = new FileSystemWatcher();
fsw.Path = @"C:\foo.txt";
fsw.Changed += new FileSystemEventHandler(LogFileChanged);

private void LogFileChanged(object s, FileSystemEventArgs e)
{ 

}

如果我把一个断点 LogFileChanged() - >打开并编辑 foo.txt的 - >保存文件,断点不打。有人可以解释什么,我错过了吗?

If i put a breakpoint in LogFileChanged() -> open and edit foo.txt -> saves the file, the breakpoint doesn't hit. Can someone explain what I missed?

推荐答案

这是一个文件不是一个路径

This is a file not a path

fsw.Path = @"C:\foo.txt";

您需要设置

fsw.Path = @"C:\";
fsw.Filter = "foo.txt";

筛选器属性

这篇关于FileSystemWatcher的更改不会触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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