Example #1
0
        private void ClearOutOfRangeItems()
        {
            if (this.previewCount <= 0)
            {
                return;
            }

            // Determine which slots are in range of a client
            bool[] inRange = new bool[this.previewCount];
            foreach (PreviewImageServiceClient client in this.clients.Items)
            {
                inRange[client.PreviewIndex] = true;
                for (int i = 1; i <= PreviewImageCacheDistance; i++)
                {
                    if (client.PreviewIndex - i >= 0)
                    {
                        inRange[client.PreviewIndex - i] = true;
                    }

                    if (client.PreviewIndex + i < this.previewCount)
                    {
                        inRange[client.PreviewIndex + i] = true;
                    }
                }
            }

            // Remove out of range items from work queue
            var newWorkQueue = new Queue <PreviewImageJob>();

            while (this.previewImageWorkQueue.Count > 0)
            {
                PreviewImageJob job = this.previewImageWorkQueue.Dequeue();
                if (inRange[job.PreviewIndex])
                {
                    newWorkQueue.Enqueue(job);
                }
            }

            // Remove out of range cache entries
            for (int i = 0; i < this.previewCount; i++)
            {
                if (!inRange[i])
                {
                    this.previewImageCache[i] = null;
                }
            }
        }
Example #2
0
        private void ClearOutOfRangeItems()
        {
            // Remove out of range items from work queue
            var newWorkQueue = new Queue <PreviewImageJob>();

            while (this.previewImageWorkQueue.Count > 0)
            {
                PreviewImageJob job = this.previewImageWorkQueue.Dequeue();
                if (Math.Abs(job.PreviewNumber - this.SelectedPreview) <= PreviewImageCacheDistance)
                {
                    newWorkQueue.Enqueue(job);
                }
            }

            // Remove out of range cache entries
            for (int i = 0; i < this.previewCount; i++)
            {
                if (Math.Abs(i - this.SelectedPreview) > PreviewImageCacheDistance)
                {
                    this.previewImageCache[i] = null;
                }
            }
        }