I know the MS shortcomongs are well covered in other blogs. It was obvious that there was not inbuilt support in WPF for “Single Instance Applications”. But lo and behold even WindowsForms applications (with Enable application framework + Make single instance application) have inconsistant (broken) behaviour when run programatically. That is multiple instances can run when the executable is evoked from Process.Start().
There are a lot of suggestions out there. The simplest fix for our framework was a simple check in the Application_Startup event in WPF and MyApplication_Startup event in WindowsForms:
Process c = Process.GetCurrentProcess();
foreach (Process p in Process.GetProcessesByName(c.ProcessName))
{
if (p.Id != c.Id)
{
// do something first
c.Kill();
}
}
Shortcomings: must be a unique process name…



Add A Comment