我试图开发概念WCF web服务的证明,它使用FileSystemWatcher类听一个目录,并简单地输出变化的类型和被更改的文件的完整路径。WCF服务来监视文件目录更改
我有一个示例控制台应用程序如预期其工作,但是当我端口为WCF库这个文件更改事件处理程序永远不会触发。
代码:
public void MonitorFolder()
{
System.IO.FileSystemWatcher watcher = new System.IO.FileSystemWatcher();
watcher.Path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "folder-to-watch");
watcher.IncludeSubdirectories = false;
watcher.Changed += watcher_Changed;
watcher.Filter = "*.*";
watcher.NotifyFilter = NotifyFilters.LastAccess |
NotifyFilters.LastWrite |
NotifyFilters.FileName |
NotifyFilters.DirectoryName;
watcher.EnableRaisingEvents = true;
}
void watcher_Changed(object sender, System.IO.FileSystemEventArgs e)
{
Console.WriteLine(string.Format("Change: {0}, File: {1}", e.ChangeType, e.FullPath));
}
和调用服务的客户端类中:
static void Main(string[] args)
{
FileListenerClient c = new FileListenerClient();
c.MonitorFolder();
c.Close();
}
任何想法为什么不拿起文件的变化?
感谢的读你的回应 - 该服务现在没有任何变化工作。不确定自己修复了什么,但是发生了变化,被事件处理程序捕获 – andrewb