Singelton CF Apps
-
Hello Everyone, I've searched some posts and articles, and I can't seem to find a good example of making a cf app single instance only. I see that some posts use various Mutex classes that are not fully featured in the cf. Has anyone come across a solution to this? Thanks, Ryan
-
Hello Everyone, I've searched some posts and articles, and I can't seem to find a good example of making a cf app single instance only. I see that some posts use various Mutex classes that are not fully featured in the cf. Has anyone come across a solution to this? Thanks, Ryan
I think that OpenNetCF has a named mutex implementation that can be used across different processes, but I am not sure about it. The most common solution is to check if a Window is already present and not start a new process:
[DllImport("coredll.dll", EntryPoint="FindWindow")] private static extern IntPtr FindWindow(string lpClassName,string lpWindowName); [DllImport("coredll.dll")] private static extern int SetForegroundWindow(IntPtr hWnd); [MTAThread] static void Main(string [] args) { string windowName = "MyForm"; IntPtr window = FindWindow(windowName); if (window == IntPtr.Zero) { Application.Run(new MainForm(windowName)); } else { SetForegroundWindow(window); } }
This is not a bullet proof solution, but it works.