Example #1
0
        public NewsCollector()
        {
            NewsSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <NewsSettings>();

            _work = new IntervalWork(RefreshFeeds, TimeSpan.FromMinutes(settings.RefreshInterval));
            ServiceRegistration.Get <IThreadPool>().AddIntervalWork(_work, true);
        }
 public void Startup()
 {
     _messageQueue.Start();
     DoStartup();
     _work = new IntervalWork(DoWork, new TimeSpan(0, 0, 20));
     ServiceRegistration.Get <IThreadPool>().AddIntervalWork(_work, false);
 }
        /// <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);
        }
Example #4
0
        public ResourceAccessModule(OwinMiddleware next) : base(next)
        {
            AddDefaultMimeTypes();
            IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>();

            _tidyUpCacheWork = new IntervalWork(TidyUpResourceAccessorCache, CACHE_CLEANUP_INTERVAL);
            threadPool.AddIntervalWork(_tidyUpCacheWork, false);
        }
 private void StopWorker()
 {
     if (_work != null)
     {
         _work.Cancel();
         ServiceRegistration.Get <IThreadPool>().RemoveIntervalWork(_work);
     }
     _work = null;
 }
Example #6
0
 public void Dispose()
 {
     if (_tidyUpCacheWork != null)
     {
         IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>();
         threadPool.RemoveIntervalWork(_tidyUpCacheWork);
         _tidyUpCacheWork = null;
     }
     ClearResourceAccessorCache();
 }
        public TranscodingServicePlugin()
        {
            _profileManager = new TranscodeProfileManager();
            ServiceRegistration.Set <ITranscodeProfileManager>(_profileManager);
            Logger.Debug("TranscodingService: Registered TranscodeProfileManager.");

            _analysisLibraryManager = new AnalysisLibraryManager();

            _settings = new SettingsChangeWatcher <TranscodingServiceSettings>();
            _settings.SettingsChanged = OnSettingsChanged;
            _settings.Refresh();

            _tidyUpCacheWork = new IntervalWork(TidyUpCache, CACHE_CLEANUP_INTERVAL);
            IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>();

            threadPool.AddIntervalWork(_tidyUpCacheWork, false);
        }
Example #8
0
        public void TestIntervalWork()
        {
            ThreadPoolStartInfo tpsi = new ThreadPoolStartInfo(2, 10, 1000);

            _pool = new ThreadPool(tpsi);
            SetupLogging();
            IntervalWork iWork = new IntervalWork(new DoWorkHandler(delegate() { TestIntervalWorkRuns++; }),
                                                  new TimeSpan(0, 0, 1));

            iWork.Description = "TestIntervalWork";
            _pool.AddIntervalWork(iWork, true);
            while (TestIntervalWorkRuns < 2)
            {
                Thread.Sleep(100);
            }
            _pool.RemoveIntervalWork(iWork);
            Assert.AreEqual(2, _pool.WorkItemsProcessed);
        }
Example #9
0
 public NewsCollector()
 {
     _settings.SettingsChanged += (sender, args) => RefreshFeeds();
     _work = new IntervalWork(RefreshFeeds, TimeSpan.FromMinutes(_settings.Settings.RefreshInterval));
     ServiceRegistration.Get <IThreadPool>().AddIntervalWork(_work, true);
 }
Example #10
0
 public void ChangeRefreshInterval(int minutes)
 {
     ServiceRegistration.Get <IThreadPool>().RemoveIntervalWork(_work);
     _work = new IntervalWork(RefreshFeeds, TimeSpan.FromMinutes(minutes));
     ServiceRegistration.Get <IThreadPool>().AddIntervalWork(_work, true);
 }