微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

线程并行调用,动作

我的代码如下

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

Visual Basic捕获cmd的输出

Windows从多图标文件中select错误的图标,并自我渲染以更正大小

分布式键/值存储可以在Windows上运行,并具有.Net客户端?

如果我对Windows服务进行了更改,是否必须运行installutil.exe?

InvisibleOperationException隐藏窗口时

从本地C调用.NET托pipe代码

Python脚本输出使用C#redirect

login/模仿作为本地/域名用户从他们作为pipe理员启动的应用程序

当应用程序是服务时,SetWinEventHookcallback不起作用

如何强制Dns.GetHostAddresses .NET方法查询DNS或DNScaching?

请检查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 Dominik

在你的情况下,如果你使用它更容易

Parallel.ForEach

在你的字符串列表而不是使用

Parallel.Invoke

附加参数。 让我知道如果你想坚持Parallel.Invoke。

Parallel.Invoke在你的代码传递一个Action<string>数组的时候接受Action数组。 你可以做的是:

public void DownloadConcurrent(Action<string> Methord) { Action<string>[] methordList = new Action<string>[Concurent_Downloads]; var r = methordList.Select(a => (Action)(() => a("some_str"))).ToArray(); Parallel.Invoke(r); }

您需要用每个操作的正确值替换some_str

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐