【发布时间】:2014-02-21 20:38:21
【问题描述】:
快速解释。 我有一个在运行时编写 console.log 文件的游戏服务器。我正在尝试创建一个在进行新更改时读取文件的事件。
如果我从文本编辑器保存文档,我的 changeevent 运行良好。但不是在服务器写入时。
当我在运行时打开日志文件时,我可以看到文档中的所有行都写得很好。
为什么我没有调用事件?
代码:
class Collect
{
public FileSystemWatcher watcher = new FileSystemWatcher("C:\\.q2online\\action\\logs\\");
public Collect()
{
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Filter = "console.log";
watcher.EnableRaisingEvents = true;
}
private static void OnChanged(object scource, FileSystemEventArgs e)
{
Debug.WriteLine(ReadLastLineFromFile(DataContainer.path.Default.logFilePath));
}
【问题讨论】:
标签: c# events event-handling onchange filesystemwatcher