Reusing Windows Picture and Fax Viewer process to load a new image from FileSystemWatcher
Posted
by Cory Larson
on Stack Overflow
See other posts from Stack Overflow
or by Cory Larson
Published on 2010-05-10T19:09:34Z
Indexed on
2010/05/10
19:14 UTC
Read the original article
Hit count: 364
So for an idea for my birthday party I'm setting up a photo booth. I've got software to remotely control the camera and all that, but I need to write a little application to monitor the folder where the pictures get saved and display them.
Here's what I've got so far. The issue is that I don't want to launch a new Windows Photo Viewer process every time the FileSystemWatcher sees a new file, I just want to load the latest image into the current instance of the Windows Photo Viewer (or start a new one if one isn't running).
class Program
{
static void Main(string[] args)
{
new Program().StartWatching();
}
public void StartWatching()
{
FileSystemWatcher incoming = new FileSystemWatcher();
incoming.Path = @"G:\TempPhotos\";
incoming.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName;
incoming.Filter = "*.jpg";
incoming.Created += new FileSystemEventHandler(ShowImage);
incoming.EnableRaisingEvents = true;
Console.WriteLine("Press \'q\' to quit.");
while (Console.Read() != 'q') ;
}
private void ShowImage(object source, FileSystemEventArgs e)
{
string s1 = Environment.ExpandEnvironmentVariables("%windir%\\system32\\rundll32.exe ");
string s2 = Environment.ExpandEnvironmentVariables("%windir%\\system32\\shimgvw.dll,ImageView_Fullscreen " + e.FullPath);
Process.Start(s1, s2);
Console.WriteLine("{0} : Image \"{0}\" at {1:t}.", e.ChangeType, e.FullPath, DateTime.Now);
}
}
If you don't have a tried and true solution, a simple push in the right direction would be just as valuable. And FYI, this will be running on a 64-bit Windows 7 machine.
Thanks!
© Stack Overflow or respective owner