public void Dispose()
 {
     if (_tidyUpCacheWork != null)
     {
         IThreadPool threadPool = ServiceRegistration.Get<IThreadPool>();
         threadPool.RemoveIntervalWork(_tidyUpCacheWork);
         _tidyUpCacheWork = null;
     }
     ClearResourceAccessorCache();
 }
Exemple #2
0
    /// <summary>
    /// Creates or removes <see cref="IIntervalWork"/> from <see cref="IThreadPool"/>.
    /// </summary>
    /// <param name="psc">IPlayerSlotController</param>
    /// <param name="starting"><c>true</c> if starting, <c>false</c> if stopping.</param>
    /// <returns><c>true</c> if work should be removed when done.</returns>
    private bool HandleTasks(IPlayerSlotController psc, bool starting)
    {
      IThreadPool threadPool = ServiceRegistration.Get<IThreadPool>();
      lock (_syncObj)
      {
        // On stop, abort background interval work
        if (!starting && _progressUpdateWorks.ContainsKey(psc))
        {
          threadPool.RemoveIntervalWork(_progressUpdateWorks[psc].Work);
          return true;
        }

        // When starting, create an asynchronous work and exit here
        if (!_progressUpdateWorks.ContainsKey(psc))
        {
          IntervalWork work = new IntervalWork(() => HandleScrobble(psc, true), UPDATE_INTERVAL);
          threadPool.AddIntervalWork(work, false);
          _progressUpdateWorks[psc] = new PositionWatcher { Work = work };
        }
      }
      return false;
    }
 public void Startup()
 {
   DoStartup();
   _work = new IntervalWork(DoWork, new TimeSpan(0, 0, 20));
   ServiceRegistration.Get<IThreadPool>().AddIntervalWork(_work, false);
 }
 private void StopWorker()
 {
   if (_work != null)
   {
     _work.Cancel();
     ServiceRegistration.Get<IThreadPool>().RemoveIntervalWork(_work);
   }
   _work = null;
 }
 public void ChangeRefreshInterval(int minutes)
 {
   ServiceRegistration.Get<IThreadPool>().RemoveIntervalWork(_work);
   _work = new IntervalWork(RefreshFeeds, TimeSpan.FromMinutes(minutes));
   ServiceRegistration.Get<IThreadPool>().AddIntervalWork(_work, true);
 }
 public NewsCollector()
 {
   NewsSettings settings = ServiceRegistration.Get<ISettingsManager>().Load<NewsSettings>();
   _work = new IntervalWork(RefreshFeeds, TimeSpan.FromMinutes(settings.RefreshInterval));
   ServiceRegistration.Get<IThreadPool>().AddIntervalWork(_work, true);
 }
 public ResourceAccessModule()
 {
   AddDefaultMimeTypes();
   IThreadPool threadPool = ServiceRegistration.Get<IThreadPool>();
   _tidyUpCacheWork = new IntervalWork(TidyUpResourceAccessorCache, CACHE_CLEANUP_INTERVAL);
   threadPool.AddIntervalWork(_tidyUpCacheWork, false);
 }