예제 #1
0
        private void Stop(TailListenerThread thread, bool remove = true)
        {
            if (thread != null)
            {
                _logger.Verbose("Stopping thread #{0}...", thread.Id);

                // Stop the thread.
                var handle = thread.Stop();

                // Wait for the thread to stop.
                _logger.Verbose("Waiting for thread #{0} to stop...", thread.Id);
                handle.WaitOne();

                if (remove)
                {
                    // Remove the thread from the collection.
                    _logger.Verbose("Removing thread #{0}...", thread.Id);
                    _threads.Remove(thread);
                }

                _logger.Verbose("Thread #{0} was stopped.", thread.Id);

                // Notify that the thread was stopped.
                _eventAggregator.Publish(new StoppedListeningEvent(thread.Id));
            }
        }
예제 #2
0
        public void Start(ITailStreamListener streamListener, ITailStreamContext streamContext)
        {
            lock (_lock)
            {
                // Create the thread.
                var id = Interlocked.Increment(ref _counter);

                // Notify about a new thread.
                _eventAggregator.Publish(new StartedListeningEvent(id, streamContext.GetDescription(), streamContext.GetName()));

                // Initialize the listener.
                streamListener.Initialize(streamContext);

                // Create the thread.
                var callback = new TailListenerThreadCallback(id, Publish);
                var thread   = new TailListenerThread(id, callback, streamListener, streamContext);
                thread.Start();

                _logger.Information("Created thread with id #{0} ({1}).", id, streamContext.GetDescription());

                // Add the thread to the collection.
                _threads.Add(thread);
            }
        }
예제 #3
0
        public void Start(ITailStreamListener streamListener, ITailStreamContext streamContext)
        {
            lock (_lock)
            {
                // Create the thread.
                var id = Interlocked.Increment(ref _counter);

                // Notify about a new thread.
                _eventAggregator.Publish(new StartedListeningEvent(id, streamContext.GetDescription(), streamContext.GetName()));

                // Initialize the listener.
                streamListener.Initialize(streamContext);

                // Create the thread.
                var callback = new TailListenerThreadCallback(id, Publish);
                var thread = new TailListenerThread(id, callback, streamListener, streamContext);
                thread.Start();

                _logger.Information("Created thread with id #{0} ({1}).", id, streamContext.GetDescription());

                // Add the thread to the collection.
                _threads.Add(thread);
            }
        }
예제 #4
0
        private void Stop(TailListenerThread thread, bool remove = true)
        {
            if (thread != null)
            {
                _logger.Verbose("Stopping thread #{0}...", thread.Id);

                // Stop the thread.
                var handle = thread.Stop();

                // Wait for the thread to stop.
                _logger.Verbose("Waiting for thread #{0} to stop...", thread.Id);
                handle.WaitOne();

                if (remove)
                {
                    // Remove the thread from the collection.
                    _logger.Verbose("Removing thread #{0}...", thread.Id);
                    _threads.Remove(thread);
                }

                _logger.Verbose("Thread #{0} was stopped.", thread.Id);

                // Notify that the thread was stopped.
                _eventAggregator.Publish(new StoppedListeningEvent(thread.Id));
            }
        }