OpenMetaverse.TexturePipeline.DownloadThread C# (CSharp) Method

DownloadThread() private method

Master Download Thread, Queues up downloads in the threadpool
private DownloadThread ( ) : void
return void
        private void DownloadThread()
        {
            int reqNbr;

            while (running)
            {
                if (requestQueue.Count > 0)
                {
                    reqNbr = -1;
                    // find available slot for reset event
                    for (int i = 0; i < threadpoolSlots.Length; i++)
                    {
                        if (threadpoolSlots[i] == -1)
                        {
                            threadpoolSlots[i] = 1;
                            reqNbr = i;
                            break;
                        }
                    }

                    if (reqNbr != -1)
                    {
                        TaskInfo task = null;
                        lock (syncObject)
                        {
                            if (requestQueue.Count > 0)
                            {
                                task = requestQueue[0];
                                requestQueue.RemoveAt(0);
                            }
                        }

                        if (task != null)
                        {
                            task.RequestNbr = reqNbr;

                            Logger.DebugLog(String.Format("Sending Worker thread new download request {0}", reqNbr));
                            ThreadPool.QueueUserWorkItem(TextureRequestDoWork, task);
                            continue;
                        }
                    }
                }

                // Queue was empty, let's give up some CPU time
                Thread.Sleep(500);
            }

            Logger.Log("Texture pipeline shutting down", Helpers.LogLevel.Info);
        }