Skip to main content

Posts

Showing posts from April, 2014

Single Instance Form Application in C#

Main function of window application  [STAThread]         static void Main()         {             if (SingleInstanceCode.SingleInstanceClass.CheckForOtherApp("{2D484E4F-9080-4D30-B12C-87405DD609AC}"))//Unique key             {                 MessageBox.Show("Application is already running.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);                 return;             }             Application.EnableVisualStyles();             Application.SetCompatibleTextRenderingDefault(false);             Application.Run(new Form1());       } SingleInstCode Class  using System; using System.Collections.Generic; using System.Windows.Forms; using System.Threading; using System.ComponentModel; using System.Runtime.InteropServices; namespace SingleInstanceCode {   static public class SingleInstanceClass   {     // Add "global\" in front of the EventName, then only one instance is allowed on the     // whole s