public static void Main_WinTrayApp(CustomApplicationContext _CustomApplicationContext, string _sApplicationName, bool _bShouldRunAsSingleInstance) { try { bool createdNew = true; Process currentProcess = Process.GetCurrentProcess(); string sAppName = (string.IsNullOrWhiteSpace(_sApplicationName) == true) ? currentProcess.ProcessName : _sApplicationName.RemoveWhiteSpace(); using (Mutex mutex = new Mutex(true, sAppName, out createdNew)) { // SKislyuk 11/3/2016 2:23:09 PM // if the app can run as multiple instances app then disregard the mutex createdNew = (_bShouldRunAsSingleInstance == true) ? createdNew : true; if (createdNew) { if (_CustomApplicationContext == null) { throw new Exception("The CustomApplicationContext class is not initialized."); } Application.Run(_CustomApplicationContext); } else { ShowProcess(); } } } catch (Exception exp) { Logger.WriteErrorLogOnly(exp, "b4d12487-4e99-4ed9-a9f4-38e02de2f41f"); Logger.DisplayError(exp.Message); } }