我遇到的问题是文件系统监视器没有捕获添加到文件夹的第一个文件,但每个后续操作都会触发。
我正在观看的文件夹位于网络共享中。
代码:
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();
}
}
}
答案 0 :(得分:0)
在创建和启用FileSystemWatcher之前,文件是否可能存在 ?