gpt4 book ai didi

c# - 线程并行调用、操作

转载 作者:可可西里 更新时间:2023-11-01 13:53:56 27 4
gpt4 key购买 nike

我的代码如下

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 出现错误:

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

它调用的方法是

public void DownloadLinks(string Term)
{
}

最佳答案

像下面这样检查 Parallel.ForEach

   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);
}

这应该对你有用

HTH多米尼克

关于c# - 线程并行调用、操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6533401/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com