parallel.foreach multiple arguments being passed to method

I am calling a method in parallel which works fine, but I want to have it pass a object to it.

This works:

static void main()
{
Parallel.ForEach(_queued, new ParallelOptions { MaxDegreeOfParallelism = config.downloadthreads }, DownloadFile);
}
public static void DownloadFile(string url)
{....
}

But what I want to do is to pass config which is a class I have defined earlier to the downloadfile method. I have been keeping my settings and other stuff in the class and then updating them so that I don't need to pass variables all over the place. But when I try that, I get a bunch of errors

cannot convert from void to system.action , _queued is a concurrentqueue

Parallel.ForEach(_queued, new ParallelOptions 
{ MaxDegreeOfParallelism = config.downloadthreads }, DownloadFile(_queued, config));

public static void DownloadFile(string url, blogconfig tumblogconfig)

Answers


You need to create a lambda and call your function from inside it.

Parallel.ForEach(_queued, 
                 new ParallelOptions { MaxDegreeOfParallelism = config.downloadthreads }, 
                 (q) => DownloadFile(q, config));

Need Your Help

How to remove a-tag's title param in tt_news using typoscript

hyperlink typo3 typoscript tt-news

The standard output of a tt_news list view hyperlink is like: