示例#1
0
        private async void ProcessQueue()
        {
            var activeJobs = new List <Task>();

            do
            {
                while (activeJobs.Count < ConcurrentWorkers && queue.TryDequeue(out var worker))
                {
                    Interlocked.Increment(ref activeJobCount);

                    if (settings.MinimummDelayBetweenRequests > 0)
                    {
                        await Task.Delay(settings.MinimummDelayBetweenRequests);
                    }

                    activeJobs.Add(worker.SyncAsync());
                }

                if (activeJobs.Count > 0)
                {
                    await Task.WhenAny(activeJobs);

                    activeJobs = activeJobs.Where(x => !x.IsCompleted).ToList();

                    Volatile.Write(ref activeJobCount, activeJobs.Count);
                }
                else
                {
                    statusReporter.FinishReport();// should only report if it has been set dirty. This happens only if someone has reported data.
                    Thread.Sleep(100);
                }
            } while (enabled);
        }
示例#2
0
        private async void ProcessQueue()
        {
            var activeJobs = new List <Task>();

            do
            {
                while (activeJobs.Count < ConcurrentWorkers && this.queue.TryDequeue(out var worker))
                {
                    activeJobs.Add(worker.SyncAsync());
                }

                if (activeJobs.Count > 0)
                {
                    await Task.WhenAny(activeJobs);

                    activeJobs = activeJobs.Where(x => !x.IsCompleted).ToList();
                }
                else
                {
                    statusReporter.FinishReport();// should only report if it has been set dirty. This happens only if someone has reported data.
                    Thread.Sleep(100);
                }
            } while (this.enabled);
        }