FileSystemWatcher在第二次更改后触发事件,但不是第一次

本文关键字:事件 第一次 第二次 FileSystemWatcher | 更新日期: 2023-09-27 18:08:16

我遇到了一个问题,文件系统监视器没有捕捉到添加到文件夹中的第一个文件,但每个后续操作都可以正常执行。

我正在查看的文件夹位于网络共享中。

代码:

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在第二次更改后触发事件,但不是第一次

是否有可能在创建并启用FileSystemWatcher之前该文件已经存在 ?