Пример #1
0
        static void Main()
        {
            // Use the assembly GUID as the name of the mutex which we use to detect if an application instance is already running
            bool   createdNew = false;
            string mutexName  = System.Reflection.Assembly.GetExecutingAssembly().GetType().GUID.ToString();

            using (System.Threading.Mutex mutex = new System.Threading.Mutex(false, mutexName, out createdNew))
            {
                if (!createdNew)
                {
                    // Only allow one instance
                    return;
                }

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                try
                {
                    STAApplicationContext context = new STAApplicationContext();
                    Application.Run(context);
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message, "Error");
                }
            }
        }
Пример #2
0
        static void Main()
        {
            Logging SystemTrayIconLogger = new Logging("SystemTrayApp");

            if (SystemTrayIconLogger != null)
            {
                Console.WriteLine($"Log: {SystemTrayIconLogger.LogPath}");
            }

            Log = SystemTrayIconLogger.Log;

            // Use the assembly GUID as the name of the mutex which we use to detect if an application instance is already running
            bool   createdNew = false;
            string mutexName  = Assembly.GetExecutingAssembly().GetType().GUID.ToString();

            using (Mutex mutex = new Mutex(false, mutexName, out createdNew))
            {
                if (!createdNew)
                {
                    // Only allow one instance
                    return;
                }

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                STAApplicationContext applicationContext = new STAApplicationContext();
                try
                {
                    Application.Run(applicationContext);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error");
                    Program.Log.Error("Main", ex);
                }
            }

            if (SystemTrayIconLogger != null)
            {
                SystemTrayIconLogger.Close();
            }
        }