![](/img/trans.png)
[英]Windows Service with FileSystemWatcher stops after the first event
[英]FileSystemWatcher Fires Event After Second Change, But Not First
我遇到了一个问题,文件系统监视器无法捕获添加到文件夹中的第一个文件,但是所有后续操作都能正常运行。
我正在查看的文件夹位于网络共享中。
码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace RTTService
{
class FileSystemMonitors : IDisposable
{
FileSystemWatcher WatchFolder = new FileSystemWatcher();
public void StartMonitoringDropFolder()
{
WatchFolder.Path = @"\\<<NETWORKED SHARE>>\inetpub\mailroot\";
WatchFolder.NotifyFilter = WatchFolder.NotifyFilter | NotifyFilters.FileName;
WatchFolder.NotifyFilter = WatchFolder.NotifyFilter | NotifyFilters.Attributes;
WatchFolder.Created += new FileSystemEventHandler(WatchFolder_Action);
WatchFolder.Deleted += new FileSystemEventHandler(WatchFolder_Action);
WatchFolder.Changed += new FileSystemEventHandler(WatchFolder_Action);
WatchFolder.EnableRaisingEvents = true;
}
void WatchFolder_Action(object sender, FileSystemEventArgs e)
{
if (e.ChangeType == WatcherChangeTypes.Changed)
{
using (Email Email = new Email())
{
Email.ParseInterpretStoreDropFolderForAllMessages(false, false, false);
}
}
}
public void Dispose()
{
WatchFolder.Dispose();
}
}
}
创建和启用FileSystemWatcher 之前文件是否存在?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.