Hello,
I have a List with items that I want to download. I use a for Loop to iterate the list.
For each item in this List I start a new Thread that references the item. My Problem is that I want limit the maxDownload at the same time.
for (int i = downloadList.Count - 1; i >= 0; i--)
{
downloadItem item = downloadList[i];
if (item.Status != 1 && item.Status != 2)
{
ThreadStart starter = delegate { this.DownloadItem(ref item); };
Thread t = new Thread(starter);
t.IsBackground = true;
t.Name = item.Name;
t.Priority = ThreadPriority.Normal;
t.Start();
}
}
I read something about the ThreadPool, but then I can't reference my item. Can someone Help me? Thanks! :)
Edit:
I tested this:
ThreadPool.SetMaxThreads(maxDownloads, maxDownloads);
ThreadPool.SetMinThreads(maxDownloads, maxDownloads);
ThreadPool.QueueUserWorkItem(DownloadItem, ref item);
I don't know how I can reference my downloadItem with this thread.....