BF2Statistics.Program.Main C# (CSharp) Method

Main() private method

private Main ( string args ) : void
args string
return void
        static void Main(string[] args)
        {
            // Enable application visual styling
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Set Exception Handler
            Application.ThreadException += ExceptionHandler.OnThreadException;
            AppDomain.CurrentDomain.UnhandledException += ExceptionHandler.OnUnhandledException;

            // Create Error Log Writter object
            ErrorLog = new LogWriter(Path.Combine(Application.StartupPath, "Logs", "Error.log"));

            // We only allow 1 instance of this application to run at a time, to prevent all kinds of issues with sockets and such
            // A Mutex will allow us to easily require 1 instance
            bool createdNew = true;
            using (Mutex mutex = new Mutex(true, "BF2Statistics Control Center", out createdNew))
            {
                if (createdNew)
                {
                    // Load the main form!
                    Application.Run(new MainForm());
                }
                else
                {
                    // Alert the user
                    MessageBox.Show(
                        "BF2Statistics Control Center is already running. Only one instance of this application can run at a time.",
                        "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning
                    );
                }
            }
        }