private void StopTasks(bool suspending)
        {
            try
              {
            Utils.SetIsStopping(true);
            if (Utils.GetDbm() != null)
              Utils.GetDbm().StopScraper = true;

            try
            {
              UtilsMovingPictures.DisposeMovingPicturesLatest();
            }
            catch { }

            try
            {
              UtilsTVSeries.DisposeTVSeriesLatest();
            }
            catch { }

            // ISSUE: method pointer
            GUIWindowManager.OnActivateWindow -= new GUIWindowManager.WindowActivationHandler(GuiWindowManagerOnActivateWindow);
            GUIWindowManager.Receivers -= new SendMessageHandler(GUIWindowManager_OnNewMessage);
            g_Player.PlayBackStarted -= new g_Player.StartedHandler(OnPlayBackStarted);
            g_Player.PlayBackEnded -= new g_Player.EndedHandler(OnPlayBackEnded);

            var num = 0;
            while (Utils.GetDelayStop() && num < 20)
            {
              Thread.Sleep(500);
              checked { ++num; }
            }

            StopScraperNowPlaying();
            if (MyFileWatcher != null)
            {
              MyFileWatcher.Created -= new FileSystemEventHandler(MyFileWatcher_Created);
              MyFileWatcher.Dispose();
            }
            if (scraperTimer != null)
            {
              scraperTimer.Dispose();
            }
            if (refreshTimer != null)
            {
              refreshTimer.Stop();
              refreshTimer.Dispose();
            }
            if (MyScraperWorker != null)
            {
              MyScraperWorker.CancelAsync();
              MyScraperWorker.Dispose();
            }
            if (MyScraperNowWorker != null)
            {
              MyScraperNowWorker.CancelAsync();
              MyScraperNowWorker.Dispose();
            }
            if (MyDirectoryWorker != null)
            {
              MyDirectoryWorker.CancelAsync();
              MyDirectoryWorker.Dispose();
            }
            if (MyRefreshWorker != null)
            {
              MyRefreshWorker.CancelAsync();
              MyRefreshWorker.Dispose();
            }
            if (Utils.GetDbm() != null)
              Utils.GetDbm().Close();

            EmptyAllImages(ref ListPictureHash);
            if (FR != null && FR.ListAnyGamesUser != null)
              EmptyAllImages(ref FR.ListAnyGamesUser);
            if (FR != null && FR.ListAnyMoviesUser != null)
              EmptyAllImages(ref FR.ListAnyMoviesUser);
            if (FR != null && FR.ListAnyMoviesScraper != null)
              EmptyAllImages(ref FR.ListAnyMoviesScraper);
            if (FS != null && FS.ListSelectedMovies != null)
              EmptyAllImages(ref FS.ListSelectedMovies);
            if (FR != null && FR.ListAnyMovingPictures != null)
              EmptyAllImages(ref FR.ListAnyMovingPictures);
            if (FR != null && FR.ListAnyMusicUser != null)
              EmptyAllImages(ref FR.ListAnyMusicUser);
            if (FR != null && FR.ListAnyMusicScraper != null)
              EmptyAllImages(ref FR.ListAnyMusicScraper);
            if (FP != null && FP.ListPlayMusic != null)
              EmptyAllImages(ref FP.ListPlayMusic);
            if (FR != null && FR.ListAnyPicturesUser != null)
              EmptyAllImages(ref FR.ListAnyPicturesUser);
            if (FR != null && FR.ListAnyScorecenterUser != null)
              EmptyAllImages(ref FR.ListAnyScorecenterUser);
            if (FS != null && FS.ListSelectedMusic != null)
              EmptyAllImages(ref FS.ListSelectedMusic);
            if (FS != null && FS.ListSelectedScorecenter != null)
              EmptyAllImages(ref FS.ListSelectedScorecenter);
            if (FR != null && FR.ListAnyTVSeries != null)
              EmptyAllImages(ref FR.ListAnyTVSeries);
            if (FR != null && FR.ListAnyTVUser != null)
              EmptyAllImages(ref FR.ListAnyTVUser);
            if (FR != null && FR.ListAnyPluginsUser != null)
              EmptyAllImages(ref FR.ListAnyPluginsUser);
            if (FR != null)
              FR.ClearPropertiesRandomPerm();

            if (!suspending)
              SystemEvents.PowerModeChanged -= new PowerModeChangedEventHandler(OnSystemPowerModeChanged);

            FP = null;
            FS = null;
            FR = null;
            Utils.DelayStop = new Hashtable();
              }
              catch (Exception ex)
              {
            logger.Error("Stop: " + ex);
              }
        }
 internal void Start()
 {
     try
       {
     Utils.DelayStop = new Hashtable();
     Utils.SetIsStopping(false);
     //
     InitLogger();
     //
     logger.Info("Fanart Handler is starting.");
     logger.Info("Fanart Handler version is " + Utils.GetAllVersionNumber());
     //
     Translation.Init();
     SetupConfigFile();
     Utils.InitFolders();
     Utils.LoadSettings();
     //
     FPlay = new FanartPlaying();
     FPlayOther = new FanartPlayOther();
     FSelected = new FanartSelected();
     FSelectedOther = new FanartSelectedOther();
     FRandom = new FanartRandom();
     //
     SetupWindowsUsingFanartHandlerVisibility();
     SetupVariables();
     Utils.SetupDirectories();
     //
     logger.Debug("Default Backdrops [" + Utils.UseDefaultBackdrop + " - " + Utils.DefaultBackdropMask+"] for Music" + (Utils.DefaultBackdropIsImage ? ":"+Utils.DefaultBackdrop : "."));
     if (Utils.DefaultBackdropIsImage)
     {
       Utils.DefaultBackdropImages.Add(0, new FanartImage("", "", Utils.DefaultBackdrop, "", "", ""));
     }
     else
     {
       if (Utils.UseDefaultBackdrop)
       {
     if (!Utils.GetIsStopping() && SyncPointDefaultBackdrops == 0)
     {
       MyDefaultBackdropWorker = new DefaultBackdropWorker();
       MyDefaultBackdropWorker.ProgressChanged += new ProgressChangedEventHandler(MyDefaultBackdropWorker.OnProgressChanged);
       MyDefaultBackdropWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(MyDefaultBackdropWorker.OnRunWorkerCompleted);
       MyDefaultBackdropWorker.RunWorkerAsync();
     }
       }
     }
     logger.Debug("MyPictures SlideShow: "+Utils.Check(Utils.UseMyPicturesSlideShow));
     if (Utils.UseMyPicturesSlideShow)
     {
       if (!Utils.GetIsStopping() && SyncPointPictures == 0)
       {
     MyPicturesWorker = new PicturesWorker();
     MyPicturesWorker.ProgressChanged += new ProgressChangedEventHandler(MyPicturesWorker.OnProgressChanged);
     MyPicturesWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(MyPicturesWorker.OnRunWorkerCompleted);
     MyPicturesWorker.RunWorkerAsync();
       }
     }
     //
     logger.Debug("FanartHandler skin use: " + Utils.Check(FPlayOther.WindowsUsingFanartPlayClearArt.Count > 0) + " Play ClearArt, " +
                                           Utils.Check(FPlayOther.WindowsUsingFanartPlayGenre.Count > 0) + " Play Genres");
     logger.Debug("                        " + Utils.Check(FSelectedOther.WindowsUsingFanartSelectedClearArtMusic.Count > 0) + " Selected Music ClearArt, " +
                                           Utils.Check(FSelectedOther.WindowsUsingFanartSelectedGenreMusic.Count > 0) + " Selected Music Genres");
     logger.Debug("                        " + Utils.Check(FSelectedOther.WindowsUsingFanartSelectedStudioMovie.Count > 0) + " Selected Movie Studios, " +
                                           Utils.Check(FSelectedOther.WindowsUsingFanartSelectedGenreMovie.Count > 0) + " Selected Movie Genres, " +
                                           Utils.Check(FSelectedOther.WindowsUsingFanartSelectedAwardMovie.Count > 0) + " Selected Movie Awards");
     //
     Utils.InitiateDbm("mediaportal");
     Utils.StopScraper = false;
     //
     AddToDirectoryTimerQueue("All");
     //
     SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(OnSystemPowerModeChanged);
     //
     GUIWindowManager.OnActivateWindow += new GUIWindowManager.WindowActivationHandler(GuiWindowManagerOnActivateWindow);
     GUIWindowManager.Receivers += new SendMessageHandler(GUIWindowManager_OnNewMessage);
     //
     g_Player.PlayBackStarted += new g_Player.StartedHandler(OnPlayBackStarted);
     g_Player.PlayBackEnded += new g_Player.EndedHandler(OnPlayBackEnded);
     //
     refreshTimer = new Timer();
     refreshTimer.Interval = Utils.RefreshTimerInterval;
     refreshTimer.Elapsed += new ElapsedEventHandler(UpdateImageTimer);
     //
     if (Utils.ScraperMPDatabase)
     {
       myScraperTimer = new TimerCallback(UpdateScraperTimer);
       scraperTimer = new System.Threading.Timer(myScraperTimer, null, 1000, Utils.ScrapperTimerInterval);
     }
     //
     InitFileWatcher();
     try
     {
       UtilsMovingPictures.SetupMovingPicturesLatest();
     }
     catch { }
     //
     try
     {
       UtilsTVSeries.SetupTVSeriesLatest();
     }
     catch { }
     //
     ClearCurrProperties();
     EmptyAllProperties();
     HideScraperProgressIndicator();
     HideDummyControls();
     InitRandomProperties();
     //
     logger.Info("Fanart Handler is started.");
     logger.Debug("Current Culture: {0}", CultureInfo.CurrentCulture.Name);
       }
       catch (Exception ex)
       {
     logger.Error("Start: " + ex);
       }
       Utils.iActiveWindow = GUIWindowManager.ActiveWindow;
 }
 internal void Start()
 {
     try
       {
     Utils.DelayStop = new Hashtable();
     Utils.SetIsStopping(false);
     InitLogger();
     logger.Info("Fanart Handler is starting.");
     logger.Info("Fanart Handler version is " + Utils.GetAllVersionNumber());
     SetupConfigFile();
     Utils.InitFolders();
     Utils.LoadSettings();
     //
     FP = new FanartPlaying();
     FS = new FanartSelected();
     FR = new FanartRandom();
     //
     SetupWindowsUsingFanartHandlerVisibility();
     SetupVariables();
     Utils.SetupDirectories();
     //
     var i = 0;
     if (Utils.DefaultBackdropIsImage)
     {
       DefaultBackdropImages.Add(0, Utils.DefaultBackdrop);
     }
     else
     {
       SetupDefaultBackdrops(Utils.DefaultBackdrop, ref i);
       Utils.Shuffle(ref defaultBackdropImages);
     }
     logger.Debug("Default backdrops ["+Utils.UseDefaultBackdrop+" - "+Utils.DefaultBackdropMask+"] for Music found: " + defaultBackdropImages.Count);
     //
     i = 0;
     if (Utils.UseMyPicturesSlideShow)
     {
       InitSlideShowImages (ref i);
       Utils.Shuffle(ref slideshowImages);
     }
     logger.Debug("MyPictures backdrops "+Utils.Check(Utils.UseMyPicturesSlideShow)+" found: " + slideshowImages.Count);
     //
     Utils.InitiateDbm("mediaportal");
     MDB = MusicDatabase.Instance;
     //
     AddToDirectoryTimerQueue("All");
     InitRandomProperties();
     //
     if (Utils.ScraperMPDatabase)
     {
       myScraperTimer = new TimerCallback(UpdateScraperTimer);
       scraperTimer = new System.Threading.Timer(myScraperTimer, null, 1000, checked (Convert.ToInt32(Utils.ScraperInterval, CultureInfo.CurrentCulture) * 3600000));
     }
     //
     SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(OnSystemPowerModeChanged);
     //
     GUIWindowManager.OnActivateWindow += new GUIWindowManager.WindowActivationHandler(GuiWindowManagerOnActivateWindow);
     GUIWindowManager.Receivers += new SendMessageHandler(GUIWindowManager_OnNewMessage);
     //
     g_Player.PlayBackStarted += new g_Player.StartedHandler(OnPlayBackStarted);
     g_Player.PlayBackEnded += new g_Player.EndedHandler(OnPlayBackEnded);
     //
     refreshTimer = new Timer(250.0);
     refreshTimer.Elapsed += new ElapsedEventHandler(UpdateImageTimer);
     refreshTimer.Interval = 250.0;
     if (FR.WindowsUsingFanartRandom.ContainsKey("35") ||
     FS.WindowsUsingFanartSelectedMusic.ContainsKey("35") ||
     FS.WindowsUsingFanartSelectedScoreCenter.ContainsKey("35") ||
     FS.WindowsUsingFanartSelectedMovie.ContainsKey("35") ||
     FP.WindowsUsingFanartPlay.ContainsKey("35") ||
     Utils.UseOverlayFanart
        )
       refreshTimer.Start();
     //
     InitFileWatcher();
     try
     {
       UtilsMovingPictures.SetupMovingPicturesLatest();
     }
     catch { }
     //
     try
     {
       UtilsTVSeries.SetupTVSeriesLatest();
     }
     catch { }
     //
     logger.Info("Fanart Handler is started.");
     logger.Debug("Current Culture: {0}", CultureInfo.CurrentCulture.Name);
       }
       catch (Exception ex)
       {
     logger.Error("Start: " + ex);
       }
 }
        private void StopTasks(bool suspending)
        {
            try
              {
            Utils.SetIsStopping(true);
            if (Utils.GetDbm() != null)
              Utils.StopScraper = true;

            try
            {
              UtilsMovingPictures.DisposeMovingPicturesLatest();
            }
            catch { }
            try
            {
              UtilsTVSeries.DisposeTVSeriesLatest();
            }
            catch { }

            // ISSUE: method pointer
            GUIWindowManager.OnActivateWindow -= new GUIWindowManager.WindowActivationHandler(GuiWindowManagerOnActivateWindow);
            GUIWindowManager.Receivers -= new SendMessageHandler(GUIWindowManager_OnNewMessage);
            g_Player.PlayBackStarted -= new g_Player.StartedHandler(OnPlayBackStarted);
            g_Player.PlayBackEnded -= new g_Player.EndedHandler(OnPlayBackEnded);

            var num = 0;
            while (Utils.GetDelayStop() && num < 20)
            {
              Utils.ThreadToLongSleep();
              checked { ++num; }
            }

            StopScraperNowPlaying();
            if (MyFileWatcher != null)
            {
              MyFileWatcher.Created -= new FileSystemEventHandler(MyFileWatcher_Created);
              MyFileWatcher.Dispose();
            }
            if (scraperTimer != null)
            {
              scraperTimer.Dispose();
            }
            if (refreshTimer != null)
            {
              refreshTimer.Stop();
              refreshTimer.Dispose();
            }
            if (MyScraperWorker != null)
            {
              MyScraperWorker.CancelAsync();
              MyScraperWorker.Dispose();
            }
            if (MyScraperNowWorker != null)
            {
              MyScraperNowWorker.CancelAsync();
              MyScraperNowWorker.Dispose();
            }
            if (MyDirectoryWorker != null)
            {
              MyDirectoryWorker.CancelAsync();
              MyDirectoryWorker.Dispose();
            }
            if (MyRefreshWorker != null)
            {
              MyRefreshWorker.CancelAsync();
              MyRefreshWorker.Dispose();
            }
            if (MyPicturesWorker != null)
            {
              MyPicturesWorker.CancelAsync();
              MyPicturesWorker.Dispose();
            }
            if (MyDefaultBackdropWorker != null)
            {
              MyDefaultBackdropWorker.CancelAsync();
              MyDefaultBackdropWorker.Dispose();
            }
            if (Utils.GetDbm() != null)
              Utils.GetDbm().Close();

            if (FPlay != null)
              FPlay.EmptyAllPlayImages();
            if (FSelected != null)
              FSelected.EmptyAllSelectedImages();
            if (FRandom != null)
            {
              FRandom.EmptyAllRandomImages();
              FRandom.ClearPropertiesRandom();
            }
            Logos.ClearDynLogos();
            //
            if (!suspending)
            {
              SystemEvents.PowerModeChanged -= new PowerModeChangedEventHandler(OnSystemPowerModeChanged);
            }
            //
            Utils.BadArtistsList = null;
            Utils.MyPicturesSlideShowFolders = null;
            Utils.Genres = null;
            Utils.Characters = null;
            Utils.Studios = null;
            Utils.AwardsList = null;
            //
            FPlay = null;
            FPlayOther = null;
            FSelected = null;
            FSelectedOther = null;
            FRandom = null;
            //
            Utils.DelayStop = new Hashtable();
              }
              catch (Exception ex)
              {
            logger.Error("Stop: " + ex);
              }
        }