別のスレッドにFileSystemWatcherを作成して、ディレクトリの変更を監視します。新しいファイルを追加したり、監視しようとしているディレクトリに新しいファイルをコピーしたりすると、私のイベントは発生しません。私はWindows FormsアプリケーションでFileSystemWatcherクラスを正常に使用していますので、私は単純なものがないと思います。FileSystemウォッチャーがイベントを発生させないのはなぜですか?
public partial class MainWindow : Window
{
System.IO.FileSystemWatcher watcher;
public MainWindow()
{
InitializeComponent();
System.Threading.Thread t1 = new System.Threading.Thread(MonitorDir);
t1.IsBackground = true;
t1.Start();
}
private void MonitorDir()
{
watcher = new System.IO.FileSystemWatcher("C:\\Temp","*.*");
watcher.Created += Watcher_Created;
watcher.Disposed += Watcher_Disposed;
watcher.Error += Watcher_Error;
watcher.Changed += Watcher_Changed;
while (true)
{
}
}
private void Watcher_Changed(object sender, System.IO.FileSystemEventArgs e)
{
throw new NotImplementedException();
}
private void Watcher_Error(object sender, System.IO.ErrorEventArgs e)
{
throw new NotImplementedException();
}
private void Watcher_Disposed(object sender, EventArgs e)
{
throw new NotImplementedException();
}
private void Watcher_Created(object sender, System.IO.FileSystemEventArgs e)
{
throw new NotImplementedException();
}
}
[FileSystemWatcherイベントを発火ない]の可能な重複に(http://stackoverflow.com/questions/16278783/filesystemwatcher-not-firing-events)が –
こんにちは!私はあなたからのフィードバックを得ていない、まだあなたの問題を解決するために管理していますか? –