I am using FileSystemWatcher to get the latest image from my Assets folder, i have a webcam to capture the image and save it in the Assets folder. After saving the image i get the latest image from FileSystemWatcher event. Here is my code :
//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);
}
));
}
At page load event the source of CustomerImage control is set to a default picture which is nopictureavail.jpeg, when a changes made in that particular Directory the image should populate in CustomerImage, filewatcher event fires then the error throws at
CustomerImage.Source = (ImageSource)isc.ConvertFromString(e.FullPath);
NullReferenceException Occured in presentationCore.dll