regor

regor

  • NA
  • 39
  • 0

Click Once in release application so when minimized in Task Bar it won't open another instance of the application

Oct 20 2009 4:48 AM
Hi, I have been looking in different sites to solve my problem but I haven't found any. I am using Visual Studio 2005 .NET The problem: When creating a Setup file, I set the program.cs to do a Mutex thread. Which works when the application is open and left open over the desktop but when minimized to the Task Bar I find that if I click the icon to open the application it does open it rather than show the error message. This is the code I have [STAThread] static void Main() { bool firstInstance; Mutex mutex = new Mutex(false, "Local\\" + "Calculate Time v1.2", out firstInstance); if (firstInstance) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } else { MessageBox.Show("An instance of the Time Calculator is already open, please check Taskbar or Desktop"); } } I am not sure if I am doing something wrong, but I think there should be a better way around this or a way to check when the program is minimized? Many Thanks

Answers (2)