public void CancelAll() { lock (_syncLock) { _threadPool.Stop(); _startCalled = false; } }
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; }
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 virtual void OnQueryComplete() { _threadPool.Stop(true); _resultsComponent.Title = String.Format("{0} results found", _resultsComponent.Table.Items.Count); }
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"); }