【发布时间】:2015-03-12 14:13:46
【问题描述】:
我正在使用 FileSystemWatcher 从我的 Assets 文件夹中获取最新图像,我有一个网络摄像头来捕获图像并将其保存在 Assets 文件夹中。保存图像后,我从 FileSystemWatcher 事件中获取最新图像。 这是我的代码:
//FileWatcher
private void FileWatcher()
{
path = @"..\..\Assets\WebCamImage\";
System.IO.FileSystemWatcher watcher = new FileSystemWatcher(path);
watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName;
watcher.Changed += watcher_Changed;
watcher.EnableRaisingEvents = true;
}
//Event
void watcher_Changed(object sender, FileSystemEventArgs e)
{
CustomerImage.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
new Action(
delegate()
{
CustomerImage.Source = (ImageSource)isc.ConvertFromString(e.FullPath);
}
));
}
在页面加载事件中,CustomerImage 控件的源设置为默认图片 nopictureavail.jpeg,当在该特定目录中进行更改时,图像应填充到 CustomerImage 中,filewatcher 事件触发,然后在
CustomerImage.Source = (ImageSource)isc.ConvertFromString(e.FullPath);
在presentationCore.dll中发生NullReferenceException
【问题讨论】: