【发布时间】:2017-04-17 10:55:12
【问题描述】:
我在单独的线程上创建了一个 FileSystemWatcher 来监视目录的更改。当我添加新文件或将新文件复制到我试图监控的目录中时,我的任何事件都不会触发。我已经在 Windows 窗体应用程序中成功使用了 FileSystemWatcher 类,所以我猜我遗漏了一些简单的东西。
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();
}
}
【问题讨论】:
-
您好!我还没有收到您的任何反馈,您的问题解决了吗?
标签: c# wpf filesystemwatcher