I am trying to create a single instance application using the approach described below.
The reason I tried going with this solution was because I needed to pass command lines from the second attempt to run the application in the first instance, and this seemed the easiest way to do this.
OS flavors I need to support:
- Windows XP SP3
- Windows 7 32 bit
- Windows 7 64 bit
I have work on all three OS versions, however I have one machine with Windows 7 32Bit where this happens with a CantStartSingleInstanceException .
Here is the code:
SingleInstanceController.cs:
using System; using Microsoft.VisualBasic.ApplicationServices; namespace SingleInstanceTest { public class SingleInstanceController : WindowsFormsApplicationBase { public SingleInstanceController() { IsSingleInstance = true; } protected override void OnCreateMainForm() { base.OnCreateMainForm(); Form1 f = new Form1(); MainForm = f;
Program.cs:
using System; using System.Windows.Forms; namespace SingleInstanceTest { static class Program { [STAThread] static void Main() { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); SingleInstanceController si = new SingleInstanceController();
For testing purposes, a form is simply a form containing a list that displays command line arguments.
Any ideas why this is not working on this machine? I’ve been doing this for two days and I can’t understand it ...
source share