public static void startThread() { MonitorThread oThread = new MonitorThread(); monitorThread = new Thread(new ThreadStart(oThread.Monitor)); monitorThread.Start(); }
public virtual void Stop() { UnSubscribeFromQueue(); Running = false; MonitorThread.Interrupt(); }
private void _UpdateTask() { // Create Task _MonitorThread = new MonitorThread(this); _MonitorThread.ProgressUpdate += (s, e) => Dispatcher.Invoke(new Action(() => _UpdateFrontend(e))); // Start Task _MonitorTask = Task.Run(() => _MonitorThread.MonitorLoop()); }
public void MonitorProcess() { var app = new App { Name = "cmd", Program = "cmd.exe" }; var monitor = new MonitorThread(app); try { // Process won't start until this thread is idle var waitForProcess = new Thread(delegate() { for (int i = 0; i < 30; i++) { if (monitor.Process != null) { break; } else { Thread.Sleep((i + 1) * 100); } } }); waitForProcess.Start(); waitForProcess.Join(); Console.WriteLine("test"); Assert.IsNotNull(monitor.Process); Assert.IsFalse(monitor.Process.HasExited); var process1 = monitor.Process; monitor.Process.Kill(); waitForProcess = new Thread(delegate() { for (int i = 0; i < 30; i++) { if (monitor.Process != process1) { break; } else { Thread.Sleep((i + 1) * 100); } } }); waitForProcess.Start(); waitForProcess.Join(); Assert.IsNotNull(monitor.Process); monitor.Stop(); monitor.Join(); Assert.IsTrue(monitor.Process.HasExited); } finally { monitor.Stop(); monitor.Join(); } }
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."); }
protected virtual void SubscribeToQueue() { Subscription = SubscriptionClient.GetSubscription(); Subscription.OnMessage = (queue, message) => { Log.Debug("Message received: " + message); Nudged = (QueueSystemMessages.TaskAvailable.ToString() == message); if (Nudged) { MonitorThread.Interrupt(); } }; SubscriberThread.Start(); }
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); } }
public virtual void Start() { SubscribeToQueue(); MonitorThread.Start(); Running = true; }
public void Configuration(IAppBuilder app) { MonitorThread monitorThread = new MonitorThread(); app.MapSignalR(); }