private void pieJobCheck(object sender, System.Timers.ElapsedEventArgs e) { try { _timer.Stop(); if (DateTime.Now > _nextMessage) { LocalLog.AddLine("Hourly status. Still checking every 30 seconds.."); } if (_CleanupLogs && (DateTime.Now > _nextLogCleanUp)) { LocalLog.AddLine("Starting to clean up old log files ..."); ScanManager.Common.LogCleanUp lc = new ScanManager.Common.LogCleanUp(_taskManager.ResolveToken("PieLogs", "Path"), _taskManager.ResolveToken("PieLogs", "FileExtension")); LocalLog.AddLine(lc.findOrphanFiles()); LocalLog.AddLine("Completed clean-up."); _nextLogCleanUp = DateTime.Now.AddHours(4); } // Look for free thread for (int i = 0; i < _threadPool.Length; i++) { if ((_threadPool[i] == null) || _threadPool[i].IsAvailable) { _threadPool[i] = new ScanManager.BackgroundProcessing(_taskManager); _threadPool[i].DoWork(); } } if (DateTime.Now > _nextMessage) { LocalLog.AddLine("Check complete."); _nextMessage = DateTime.Now.AddHours(1); } } catch (Exception ex) { LocalLog.AddLine("ERROR: " + ex.Message); } finally { String stopFile = String.Format("{0}{1}stop.txt", MiscUtilities.AppPath(), Path.DirectorySeparatorChar); if (File.Exists(stopFile)) { LocalLog.AddLine(String.Format("Stopping service, waiting for processes to complete. Stop file ({0}) located on the drive.", stopFile)); File.Delete(stopFile); Boolean threadsRunning = true; while (threadsRunning) { threadsRunning = false; for (int i = 0; i < _threadPool.Length; i++) { if ((_threadPool[i] != null) || _threadPool[i].IsBusy) { threadsRunning = true; break; } } if (threadsRunning) { Thread.Sleep(30000); } } Stop(); } else { _timer.Start(); } } }