示例#1
0
        public static void startThread()
        {
            MonitorThread oThread = new MonitorThread();

            monitorThread = new Thread(new ThreadStart(oThread.Monitor));
            monitorThread.Start();
        }
示例#2
0
        public virtual void Stop()
        {
            UnSubscribeFromQueue();

            Running = false;
            MonitorThread.Interrupt();
        }
示例#3
0
        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());
        }
示例#4
0
        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();
            }
        }
示例#5
0
        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.");
 }
示例#7
0
        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();
        }
示例#8
0
        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}");
            }
        }
示例#9
0
        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);
            }
        }
示例#10
0
 public virtual void Start()
 {
     SubscribeToQueue();
     MonitorThread.Start();
     Running = true;
 }
示例#11
0
        public void Configuration(IAppBuilder app)
        {
            MonitorThread monitorThread = new MonitorThread();

            app.MapSignalR();
        }