protected override void Start()
        {
            if (!_enabled)
            {
                return;
            }

            _isStarted = true;

            _imageBoxEnumerator = new ViewerFrameEnumerator(ImageViewer, SelectedImageBoxWeight, UnselectedImageBoxWeight, FrameLookAheadCount.GetValueOrDefault(-1), CanRetrieveFrame);

            _retrieveThreadPool = new FrameBlockingThreadPool(_imageBoxEnumerator, DoRetrieveFrame)
            {
                ThreadPoolName = GetThreadPoolName("Retrieve"),
                Concurrency    = RetrievalThreadConcurrency,
                ThreadPriority = _retrievalThreadPriority
            };
            _retrieveThreadPool.Start();

            if (DecompressionThreadConcurrency <= 0)
            {
                return;
            }

            _decompressThreadPool = new SimpleBlockingThreadPool(DecompressionThreadConcurrency)
            {
                ThreadPoolName = GetThreadPoolName("Decompress"),
                ThreadPriority = _decompressionThreadPriority
            };
            _decompressThreadPool.Start();
        }
示例#2
0
        private void TestChangeProperties(SimpleBlockingThreadPool pool)
        {
            string failMessage = "Not supposed to be able to change 'AllowInactiveAdd' when the thread pool is active.";

            try
            {
                pool.AllowInactiveAdd = true;
            }
            catch
            {
                failMessage = null;
            }

            if (failMessage != null)
            {
                Assert.Fail(failMessage);
            }

            failMessage = "Not supposed to be able to change 'ThreadPriority' when the thread pool is active.";
            try
            {
                pool.ThreadPriority = ThreadPriority.Highest;
            }
            catch
            {
                failMessage = null;
            }

            if (failMessage != null)
            {
                Assert.Fail(failMessage);
            }

            failMessage = "Not supposed to be able to change 'Concurrency' when the thread pool is active.";
            try
            {
                pool.Concurrency = 5;
            }
            catch
            {
                failMessage = null;
            }

            if (failMessage != null)
            {
                Assert.Fail(failMessage);
            }
        }
        protected override void Stop()
        {
            if (_retrieveThreadPool != null)
            {
                _retrieveThreadPool.Stop(false);
                _retrieveThreadPool = null;
            }

            if (_decompressThreadPool != null)
            {
                _decompressThreadPool.Stop(false);
                _decompressThreadPool = null;
            }

            if (_imageBoxEnumerator != null)
            {
                _imageBoxEnumerator.Dispose();
                _imageBoxEnumerator = null;
            }

            _isStarted = false;
        }
示例#4
0
		private void TestChangeProperties(SimpleBlockingThreadPool pool)
		{
			string failMessage = "Not supposed to be able to change 'AllowInactiveAdd' when the thread pool is active.";
			try
			{
				pool.AllowInactiveAdd = true;
			}
			catch
			{
				failMessage = null;
			}

			if (failMessage != null)
				Assert.Fail(failMessage);

			failMessage = "Not supposed to be able to change 'ThreadPriority' when the thread pool is active.";
			try
			{
				pool.ThreadPriority = ThreadPriority.Highest;
			}
			catch
			{
				failMessage = null;
			}

			if (failMessage != null)
				Assert.Fail(failMessage);

			failMessage = "Not supposed to be able to change 'Concurrency' when the thread pool is active.";
			try
			{
				pool.Concurrency = 5;
			}
			catch
			{
				failMessage = null;
			}

			if (failMessage != null)
				Assert.Fail(failMessage);
		}
示例#5
0
		public void TestSimpleThreadPool()
		{
			Initialize();

			SimpleBlockingThreadPool pool = new SimpleBlockingThreadPool(_threadCount);
			pool.ThreadPriority = ThreadPriority.Normal;

			string failMessage = "not supposed to be able to enqueue when pool is not running and AllowInactiveAdd is false";
			try
			{
				pool.Enqueue(delegate() { ; });
			}
			catch
			{
				failMessage = null;
			}

			if (failMessage != null)
				Assert.Fail(failMessage);
			
			Assert.AreEqual(pool.QueueCount, 0, "the pool should be empty.");

			ItemDelegate<int> addToPool = delegate(int numberToAdd) 
			{
				for (int i = 0; i < numberToAdd; ++i)
				{
					pool.Enqueue
					(
						delegate()
						{
							this.IncrementDequeued(1);
						}
					);
				}

				this.IncrementEnqueued(numberToAdd);
				this.IncrementExpectedDequeued(numberToAdd);
			};

			pool.Start();

			TestChangeProperties(pool);

			addToPool(100000);
			pool.Stop(false);
			
			Assert.AreNotEqual(0, pool.QueueCount, "queue is empty, but it should not be because CompleteBeforeStop is currently false");

			failMessage = null;
			try
			{
				pool.AllowInactiveAdd = true;
				addToPool(100000);
			}
			catch
			{
				failMessage = "adding to the queue should be allowed because AllowInactiveAdd is true";
			}

			if (failMessage != null)
				Assert.Fail(failMessage);

			pool.Start();

			//'pulse' the queue by letting it go empty, then adding more.
			int numberTimesAdded = 0;
			while (true)
			{
				if (pool.QueueCount == 0)
				{
					addToPool(100000);
					if (++numberTimesAdded == _threadCount)
						break;
				}

				Thread.Sleep(5);
			}

			pool.Stop(false);
			Assert.AreNotEqual(0, pool.QueueCount, "queue is empty, but it should not be because CompleteBeforeStop is currently false");

			addToPool(100000);
			pool.Start();
			pool.Stop(true);

			Assert.AreEqual(0, pool.QueueCount, "queue should be empty because CompleteBeforeStop is currently true");

			Assert.AreEqual(this.ExpectedDequeued, this.Dequeued, "expected dequeued != dequeued");
		}
示例#6
0
        public void TestSimpleThreadPool()
        {
            Initialize();

            SimpleBlockingThreadPool pool = new SimpleBlockingThreadPool(_threadCount);

            pool.ThreadPriority = ThreadPriority.Normal;

            string failMessage = "not supposed to be able to enqueue when pool is not running and AllowInactiveAdd is false";

            try
            {
                pool.Enqueue(delegate() {; });
            }
            catch
            {
                failMessage = null;
            }

            if (failMessage != null)
            {
                Assert.Fail(failMessage);
            }

            Assert.AreEqual(pool.QueueCount, 0, "the pool should be empty.");

            ItemDelegate <int> addToPool = delegate(int numberToAdd)
            {
                for (int i = 0; i < numberToAdd; ++i)
                {
                    pool.Enqueue
                    (
                        delegate()
                    {
                        this.IncrementDequeued(1);
                    }
                    );
                }

                this.IncrementEnqueued(numberToAdd);
                this.IncrementExpectedDequeued(numberToAdd);
            };

            pool.Start();

            TestChangeProperties(pool);

            addToPool(100000);
            pool.Stop(false);

            Assert.AreNotEqual(0, pool.QueueCount, "queue is empty, but it should not be because CompleteBeforeStop is currently false");

            failMessage = null;
            try
            {
                pool.AllowInactiveAdd = true;
                addToPool(100000);
            }
            catch
            {
                failMessage = "adding to the queue should be allowed because AllowInactiveAdd is true";
            }

            if (failMessage != null)
            {
                Assert.Fail(failMessage);
            }

            pool.Start();

            //'pulse' the queue by letting it go empty, then adding more.
            int numberTimesAdded = 0;

            while (true)
            {
                if (pool.QueueCount == 0)
                {
                    addToPool(100000);
                    if (++numberTimesAdded == _threadCount)
                    {
                        break;
                    }
                }

                Thread.Sleep(5);
            }

            pool.Stop(false);
            Assert.AreNotEqual(0, pool.QueueCount, "queue is empty, but it should not be because CompleteBeforeStop is currently false");

            addToPool(100000);
            pool.Start();
            pool.Stop(true);

            Assert.AreEqual(0, pool.QueueCount, "queue should be empty because CompleteBeforeStop is currently true");

            Assert.AreEqual(this.ExpectedDequeued, this.Dequeued, "expected dequeued != dequeued");
        }
		protected override void Stop()
		{
			if (_retrieveThreadPool != null)
			{
				_retrieveThreadPool.Stop(false);
				_retrieveThreadPool = null;
			}

			if (_decompressThreadPool != null)
			{
				_decompressThreadPool.Stop(false);
				_decompressThreadPool = null;
			}

			if (_imageBoxEnumerator != null)
			{
				_imageBoxEnumerator.Dispose();
				_imageBoxEnumerator = null;
			}

			_isStarted = false;
		}
		protected override void Start()
		{
			if (!_enabled)
				return;

			_isStarted = true;

			_imageBoxEnumerator = new ViewerFrameEnumerator(ImageViewer, SelectedImageBoxWeight, UnselectedImageBoxWeight, FrameLookAheadCount.GetValueOrDefault(-1), CanRetrieveFrame);

			_retrieveThreadPool = new FrameBlockingThreadPool(_imageBoxEnumerator, DoRetrieveFrame)
			                      	{
			                      		ThreadPoolName = GetThreadPoolName("Retrieve"),
			                      		Concurrency = RetrievalThreadConcurrency,
			                      		ThreadPriority = _retrievalThreadPriority
			                      	};
			_retrieveThreadPool.Start();

			if (DecompressionThreadConcurrency <= 0)
				return;

			_decompressThreadPool = new SimpleBlockingThreadPool(DecompressionThreadConcurrency)
			                        	{
			                        		ThreadPoolName = GetThreadPoolName("Decompress"),
			                        		ThreadPriority = _decompressionThreadPriority
			                        	};
			_decompressThreadPool.Start();
		}