private void StartThread(SynThread th) { th.thread = new Thread(delegate() { // Create the WaitHandle array. var handles = new WaitHandle[] { shutdownEvent, th.scheduleEvent }; // Start the timer. th.timer.Start(); // Wait for one of the events to occur. while (!shutdownEvent.WaitOne(0)) { switch (WaitHandle.WaitAny(handles)) { case 0: // Shutdown Event break; case 1: // Schedule Event th.timer.Stop(); th.scheduleEvent.Reset(); ThreadPool.QueueUserWorkItem(th.performWork.Invoke, null); break; default: shutdownEvent.Set(); // should never occur break; } } }) { IsBackground = true, Name = th.name }; th.thread.Start(); DataLayer.LogMessage(LogLevel.Service, $"Thread {th.name} started."); }
protected override void OnStart(string[] args) { thDownload = new SynThread("Download", 5000, PerformDownload); thProcessArticles = new SynThread("ProcessingArticles", 1001, PerformArticleProcessing); thProcessShingles = new SynThread("ProcessingShingles", 1111, PerformShingleProcessing); //thIntrinio = new SynThread("Intrinio", 24000 * 3600 / 450, PerformIntrinio); //thIntrinio = new SynThread("Intrinio", 24000 * 3600 / 45, PerformIntrinio); RssLogic.UpdateServerConnection(); using (var ctx = new Db()) { RssLogic.AddNewFeedsFromResource(ctx); } StartThread(thDownload); //StartThread(thProcessShingles); StartThread(thProcessArticles); //StartThread(thIntrinio); }