我想每5分鐘輪詢目錄中的文件。我不想使用filesystemwatcher。我是相當新的C#,我找不到任何好的例子如何輪詢目錄中的文件
這是我迄今爲止。我只是把它放在一個計時器?
string watchFolder = ConfigurationManager.AppSettings["watchFolder"];
DirectoryInfo directoryInfo = new DirectoryInfo(watchFolder);
if (!Directory.Exists(watchFolder))
{
Console.WriteLine(
"{0} directory does not exist. Please modify the config file accordingly.",
watchFolder);
Environment.Exit(3);
}
FileInfo[] lastUpdatedFiles = directoryInfo.GetFiles();
_Why_你不想使用FSW?這就像問我如何切水果?我不想用刀。 – SLaks
我注意到signifigant文件鎖,我發現它缺少文件。 – user2892443
當你從FileSystemWatcher獲得事件時,你實際上可以有幾個同時排隊。我處理整個我正在觀看的目錄,以便拾取所有存在的文件。至於文件鎖,這是一個時間問題,無論您如何執行此操作,都需要予以解決。 –