public void NoItemsAreProcessedAfterStop()
        {
            // Arrange
            var workerThreads = 10;
            var worker = new BackgroundWorkerQueue(workerThreads);

            var work = new List<StandardWork>();

            for (var i = 0; i < 10; i++)
            {
                work.Add(new StandardWork());
            }

            // Act
            worker.Stop();

            foreach (var w in work)
            {
                worker.Enqueue(w);
            }

            // wait for a bit
            Thread.Sleep(500);

            // Assert
            Assert.IsEmpty(PROCESSED_WORK);
        }
Ejemplo n.º 2
0
        private void CollectDealershipData(List<string[]> dealershipList, DataHub dataHub)
        {
            dealershipDataSet = new List<DealershipData>();
            var workerThreads = 99;
            using (var worker = new BackgroundWorkerQueue(workerThreads))
            {
                foreach (var dealership in dealershipList)
                {
                    var work = new DataCollector(dealership[0], new Uri(dealership[1]));
                    worker.Enqueue(work);
                }

                dataHub.SendTotal(dealershipList.Count);
                var completed = 0;
                var status = worker.Status();
                do
                {
                    if (status.Failed.Any())
                        worker.ReAddFailed(status.Failed);
                    Thread.Sleep(1000);
                    status = worker.Status();

                    if (Monitor.TryEnter(theLock, 100))
                    {
                        try
                        {
                            completed = dealershipDataSet.Count;
                        }
                        finally
                        {
                            Monitor.Exit(theLock);
                        }
                    }

                    dataHub.SendProgress(completed, status.Processing.Count(), status.Failed.Count());
                } while (status.Backlog.Any() || status.Processing.Any() || status.Failed.Any());
                worker.Stop();
                worker.ClearErrors();
                dataHub.CompleteDataCollection();
            }
        }