簡體   English   中英

FileSystemWatcher在第二次更改后觸發事件,但不是第一次

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM