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();
        }
        public void PerformSearch()
        {
            var initialSearchCommand = new AimDataServiceSearchCommand();

            initialSearchCommand.Coordinator = this;
            SearchResultsComponent.Table.Items.Clear();

            _uiThreadSynchronizationContext = SynchronizationContext.Current;

            _totalCommandsToExecute = 1;
            _commandsExecuted       = 0;

            _cancel       = false;
            _resultsAdded = false;

            SearchResultsComponent.Title = "Searching...";

            ApiKeyCredentials credentials = AimDataServiceLoginTool.Credentials;

            if (credentials == null)
            {
                AimDataServiceLoginTool.RequestLogin();
                credentials = AimDataServiceLoginTool.Credentials;
            }

            if (credentials != null)
            {
                _threadPool.Start();
                _threadPool.Enqueue(initialSearchCommand.Execute);
            }
        }
Example #3
0
        protected void PerformSearch(SearchCommand initialSearchCommand)
        {
            initialSearchCommand._coordinator = this;
            _resultsComponent.Table.Items.Clear();

            _uiThreadSynchronizationContext = SynchronizationContext.Current;

            _totalCommandsToExecute = 1;
            _commandsExecuted       = 0;

            _cancel       = false;
            _resultsAdded = false;

            _resultsComponent.Title = "Searching...";

            _threadPool.Start();
            _threadPool.Enqueue(initialSearchCommand.Execute);
        }
        protected void EnqueueCommand(RetrieveCommand command)
        {
            if (!_startCalled)
            {
                _uiThreadSynchronizationContext = SynchronizationContext.Current;
            }

            OnResultAdded(command.Result);

            Interlocked.Increment(ref _totalCommandsToExecute);
            _threadPool.Enqueue(command.Execute);

            lock (_syncLock)
            {
                _threadPool.Start();
                _startCalled = true;
            }
        }
Example #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");
		}
Example #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 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();
		}