private void MonitorGameRunning()
 {
     Task.Factory.StartNew(() =>
     {
         while (!IsGameRunning())
         {
             Thread.Sleep(1000);
         }
     }).ContinueWith(antecedent =>
     {
         DesactiverWindow();
     }, _uiScheduler).ContinueWith(antecedent2 =>
     {
         ActiverGregwareCustomizations();
         while (IsGameRunning())
         {
             Thread.Sleep(1000);
         }
     }).ContinueWith(antecedent3 =>
     {
         ActiverWindow();
     }, _uiScheduler).ContinueWith(antecedent4 =>
     {
         _fullScreenGregware.Desactiver();
         _fullScreenGregware = null;
         MonitorGameRunning();
     });
 }
        private void ActiverGregwareCustomizations()
        {
            // Initialisation
            bool isFullscreenGregware = (bool)Properties.Settings.Default["FullscreenModeGregware"];
            bool isScrollGregware     = (bool)Properties.Settings.Default["ScrollGregware"];
            bool isGentool            = (bool)Properties.Settings.Default[string.Format("Current{0}Gentool", _currentGameName)];
            int  resolutionX          = 0;
            int  resolutionY          = 0;

            // Validité
            if (!isFullscreenGregware && !isScrollGregware)
            {
                return;
            }

            // Trouver la résolution actuelle
            if (isFullscreenGregware)
            {
                string pathToOptionIni;
                if (_currentGameName.Equals("Generals", StringComparison.OrdinalIgnoreCase))
                {
                    pathToOptionIni = _pathToOptionIniGenerals;
                }
                else if (_currentGameName.Equals("HeureH", StringComparison.OrdinalIgnoreCase))
                {
                    pathToOptionIni = _pathToOptionIniHeureH;
                }
                else
                {
                    throw new Exception(string.Format("Unknown game name {0}", _currentGameName));
                }
                IniHelper.OptionIni optionIniResolution = IniHelper.GetOptionIni(pathToOptionIni);
                resolutionX = optionIniResolution.ResolutionX;
                resolutionY = optionIniResolution.ResolutionY;
            }

            // Activer
            _fullScreenGregware = new GregwareCustomizations(isFullscreenGregware, isScrollGregware, isGentool, resolutionX, resolutionY, _uiScheduler);
            _fullScreenGregware.Activer();
        }