示例#1
0
        public static void Main()
        {
            Logger.SetupStandardLogging(Path.Combine(AppDataDir, "Logging"), InCommandLineMode);

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

#if SHIPPING
            try
            {
                if (WindowUtils.BringOtherAppInstanceToFront("Build Sync - Client"))
                {
                    return;
                }

                SetConsoleCtrlHandler(
                    CtrlType =>
                {
                    if (CtrlType == CtrlTypes.CTRL_C_EVENT ||
                        CtrlType == CtrlTypes.CTRL_BREAK_EVENT ||
                        CtrlType == CtrlTypes.CTRL_CLOSE_EVENT ||
                        CtrlType == CtrlTypes.CTRL_LOGOFF_EVENT ||
                        CtrlType == CtrlTypes.CTRL_SHUTDOWN_EVENT)
                    {
                        Logger.Log(LogLevel.Warning, LogCategory.Main, "Recieved close event from console.");
                        Application.Exit();
                        return(true);
                    }

                    return(false);
                }, true
                    );

                using (new SingleGlobalInstance(100))
                {
#endif
            BuildSettings.Init();

            OnStart();

            /*
             *      PollTimer = new System.Timers.Timer(20);
             *      PollTimer.Elapsed += (object sender, ElapsedEventArgs e) =>
             *      {
             *          if (Monitor.TryEnter(PollTimer))
             *          {
             *              try
             *              {
             *                  // Make sure it invokes on main thread, maybe spend some time
             *                  // make all the ui->program interaction thread safe?
             *                  if (AppForm != null && AppForm.IsHandleCreated && !AppForm.IsDisposed && !AppForm.Disposing)
             *                  {
             *                      try
             *                      {
             *                          AppForm.Invoke((MethodInvoker)(() =>
             *                          {
             *                              OnPoll();
             *                          }));
             *                      }
             *                      catch (ObjectDisposedException)
             *                      {
             *                          // Ignore ...
             *                      }
             *                  }
             *              }
             *              finally
             *              {
             *                  Monitor.Exit(PollTimer);
             *              }
             *          }
             *      };
             *      PollTimer.Start();
             */

            AppForm = new MainForm();
            Application.Run(AppForm);

            OnStop();
#if SHIPPING
        }
    }
    catch (TimeoutException Ex)
    {
        MessageBox.Show("Application is already running.", "Already Running", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    }
#endif
        }