public static void Main(string[] args) { try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); bool isFirstInstance; // Please use a unique name for the mutex to prevent conflicts with other programs using (Mutex mtx = new Mutex(true, "TrinketFakeUsbSerialHostSW", out isFirstInstance)) { if (isFirstInstance) { TrinketFakeUsbSerialHostSW notificationIcon = new TrinketFakeUsbSerialHostSW(); notificationIcon.notifyIcon.Visible = true; Application.Run(); notificationIcon.notifyIcon.Dispose(); } else { // The application is already running // TODO: Display message box or change focus to existing application instance } } // releases the Mutex } catch (Exception ex) { MessageBox.Show("Trinket Fake USB Serial Host Software: Fatal Error: " + ex.Message); } }
public static void Main(string[] args) { try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); bool isFirstInstance; // Please use a unique name for the mutex to prevent conflicts with other programs using (Mutex mtx = new Mutex(true, "TrinketFakeUsbSerialHostSW", out isFirstInstance)) { if (isFirstInstance) { TrinketFakeUsbSerialHostSW notificationIcon = new TrinketFakeUsbSerialHostSW(); notificationIcon.notifyIcon.Visible = true; Application.Run(); notificationIcon.notifyIcon.Dispose(); } else { // The application is already running // TODO: Display message box or change focus to existing application instance } } // releases the Mutex } catch (Exception ex) { MessageBox.Show("Trinket Fake USB Serial Host Software: Fatal Error: " + ex.Message); } }