当 watcher.created 检测到有新的 dll 时,我想显示新的文件路径
我可以在初始加载时设置 watcher_change() 的值,但我不确定如何从那一点更改列出的值。当我使用由 watcher_change(object sender, FileSystemEventArgs e) 创建时,我可以看到 filePaths 具有我需要的值,我只是不确定如何让它们显示在屏幕上。
public partial class Page : UserControl
{
private FileWatch f = new FileWatch();
public Page()
{
ListBox.DataContext = f.watcher_change();
}
}
public class FileWatch
{
public FileWatch()
{
var watcher =
new FileSystemWatcher {Path = @"C:\", EnableRaisingEvents = true};
watcher.Created += (o, args) => watcher_change(o, args);
}
public string[] watcher_change(object sender, FileSystemEventArgs e)
{
string[] filePaths = Directory.GetFiles(@"C:\", "*.dll");
return filePaths;
}
public string[] watcher_change()
{
string[] filePaths = Directory.GetFiles(@"C:\", "*.dll");
return filePaths;
}
}