Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Threading Parallel Invoke, Action

My code as below

public void DownloadConcurrent(Action<string> Methord)
{
    Action<string>[] methordList = new Action<string>[Concurent_Downloads];

    for (int i = 0; i < Concurent_Downloads; i++)
    {
        methordList[i] = Methord;
    }

    Parallel.Invoke(methordList);
}

Parallel.Invoke is giving error:

"cannot convert from 'System.Action<string>[]' to 'System.Action[]'"

The Method it is calling is

public void DownloadLinks(string Term)
{ 
}
like image 748
Milan Solanki Avatar asked Feb 23 '23 17:02

Milan Solanki


1 Answers

check Parallel.ForEach like the following

   static void Main(string[] args)
    {
        List<string> p = new List<string>() { "Test", "Test2", "Test3"};
        Parallel.ForEach(p, Test);
    }


    public static void Test(string test)
    {
        Debug.WriteLine(test);
    }

This should do the trick for you

HTH Dominik

like image 98
Dominik Avatar answered Mar 08 '23 09:03

Dominik