3
我創建了FileSystem監視器並註冊了2個事件。一個是創造和其他變化。C#文件系統監視器和FIleStream編寫器
FileSystemWatcher fswInbound = new FileSystemWatcher();
fswInbound.Path = "path to directory";
fswInbound.EnableRaisingEvents = true;
fswInbound.InternalBufferSize = 12288;
fswInbound.Created += new FileSystemEventHandler(program.FileSystemWatcher_Created);
fswInbound.Changed += new FileSystemEventHandler(program.FileSystemWatcher_Created);
與我在同一個程序中動態創建文件並試圖寫入FileSystem Watcher正在偵聽的文件夾中。
using (StreamWriter outfile = new StreamWriter(filename))
{
outfile.Write("Some really long string");
}
創建新文件後。 2個事件正在被解僱。一個是爲了改變而創造的。我只想要觸發文件創建事件。我在第一次創建文件時如何避免文件更改事件?