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);
            }
        }
        private void DoRetrieveFrame(Frame frame)
        {
            try
            {
                RetrieveFrame(frame);

                if (CanDecompressFrame(frame))
                {
                    _decompressThreadPool.Enqueue(() => DoDecompressFrame(frame));
                }
            }
            catch (Exception ex)
            {
                // don't let an uncaught exception crash the entire preloader
                Platform.Log(LogLevel.Warn, ex, "An error occured while trying to preload a frame.");
            }
        }
Exemple #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;
            }
        }
		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");
		}
        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");
        }