public void Run() { try { if (_isSafetyNetRunning != true) //checking if safetynet has already been started { this.StartSafetyNet(); //watch instance numbers _isSafetyNetRunning = true; } if (_isTempCleanerRunning != true) //checking if tempcleaner has been started { TempFiles.StartTempFileWatcher(); //watch temp directory on a diff schedule _isTempCleanerRunning = true; } this._timeline = TimelineBuilder.GetLocalTimeline(); // now watch that file for changes if (timelineWatcher == null) //you can change this to a bool if you want but checks if the object has been created { _log.Trace("Timeline watcher starting and is null..."); timelineWatcher = new FileSystemWatcher(TimelineBuilder.TimelineFilePath().DirectoryName) { Filter = Path.GetFileName(TimelineBuilder.TimelineFilePath().Name) }; _log.Trace($"watching {Path.GetFileName(TimelineBuilder.TimelineFilePath().Name)}"); timelineWatcher.NotifyFilter = NotifyFilters.LastWrite; timelineWatcher.EnableRaisingEvents = true; timelineWatcher.Changed += OnChanged; } _threadJobs = new List <ThreadJob>(); //load into an managing object //which passes the timeline commands to handlers //and creates a thread to execute instructions over that timeline if (this._timeline.Status == Timeline.TimelineStatus.Run) { RunEx(this._timeline); } else { if (MonitorThread != null) { MonitorThread.Abort(); MonitorThread = null; } } } catch (Exception e) { _log.Error($"Orchestrator.Run exception: {e}"); } }
/// <summary> /// Method used to abort all open threads that are monitoring subreddits. /// </summary> /// <param name="MonitorThreads"></param> /// <param name="StatisticLines"></param> static void StopMonitoring(List <Thread> MonitorThreads, int StatisticLines) { //Set the cursor position at the bottom of the screen, past all other printed lines. Console.SetCursorPosition(0, ((int)(BotStats.TotalRepliesPosted - BotStats.RepliesPostedAtBotLaunch) + (int)BotStats.RepliesFailed + StatisticLines + (int)BotStats.OwnCommentsDeleted) + 2); Log("Stopping all threads..."); foreach (Thread MonitorThread in MonitorThreads) { MonitorThread.Abort(); } Log("All threads stopped."); }
public void Run() { try { this.StartSafetyNet(); //watch instance numbers TempFiles.StartTempFileWatcher(); //watch temp directory on a diff schedule this._timeline = TimelineBuilder.GetLocalTimeline(); // now watch that file for changes FileSystemWatcher timelineWatcher = new FileSystemWatcher(TimelineBuilder.TimelineFilePath().DirectoryName) { Filter = Path.GetFileName(TimelineBuilder.TimelineFilePath().Name) }; _log.Trace($"watching {timelineWatcher.Path}"); timelineWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.CreationTime | NotifyFilters.LastWrite; timelineWatcher.EnableRaisingEvents = true; timelineWatcher.Changed += new FileSystemEventHandler(OnChanged); _threadJobs = new List <ThreadJob>(); //load into an managing object //which passes the timeline commands to handlers //and creates a thread to execute instructions over that timeline if (this._timeline.Status == Timeline.TimelineStatus.Run) { RunEx(this._timeline); } else { if (MonitorThread != null) { MonitorThread.Abort(); MonitorThread = null; } } } catch (Exception e) { _log.Error($"Orchestrator.Run exception: {e}"); } }
public void Stop() { try { lock (this) { // Set the flag, telling the thread it's gotta wrap up. KeepWorking = false; // In case it 's waiting, signal it to stop. Monitor.Pulse(this); } // Join it for 20 millis. MonitorThread.Join(20); // if it's not done by now, abort it. MonitorThread.Abort(); // fail the current task. if (Queue.CurrentTask != null) { Queue.Fail("Service is stopping."); } // Attempt to release the application domain, if it 's there. releaseAppDomain(); Log.Info("Stopped monitor thread."); Log.DebugFormat("Thread Identifier: {0}", MonitorThread.Name); MonitorThread = null; } catch (Exception exception) { Log.Error("Failed to stop monitor thread.", exception); } }