public CalendarSyncApplication()
        { 
            // Setup the shutdown action
            Application.ApplicationExit += OnApplicationExit;

            // Create the exit icon.
            _trayMenu = new ContextMenu();

            // Add whether it runs at startup
            _trayItemRunsOnLogin = new MenuItem("Run on login", OnRunOnLoginButtonClick);
            _trayItemRunsOnLogin.Checked = ApplicationRunsAtLogon;
            _trayMenu.MenuItems.Add(_trayItemRunsOnLogin);

            // Add the "Exit" menu item
            _trayMenu.MenuItems.Add("Exit", OnTrayExit);

            // Create a tray icon, with a calendar icon
            _trayIcon = new NotifyIcon
                {
                    Text = APPLICATION_NAME,
                    Icon = new Icon("CalendarTrayIcon.ico", 40, 40),
                    ContextMenu = _trayMenu,
                    Visible = true,
                    
                };
            // Spin up a Calendar Sync Service
            _calendarSyncService = new CalendarSyncService();
        }
        public static void Main(string[] args)
        {
            if (args.Length > 0 && (args[0].Equals("--console") || args[0].Equals("-c")))
            {
                // Command line given, display console
                AllocConsole();
                var service = new CalendarSyncService();
                service.Start();

                // Spin until a "q" is pressed in the console.
                Console.WriteLine("Press 'q' to quit application");
                while (Console.ReadKey().Key != ConsoleKey.Q)
                { }

                service.Stop();
            }
            else
            {
                Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                Application.Run(new CalendarSyncApplication());
            }
        }