如何通过 Parallel::For 调用 Action<String^>

问题描述 投票:0回答:1
我的代码:

Action<String^> ^act = gcnew Action<String^>(this, &Form1::loadFileInternam); System::Threading::Tasks::Parallel::For(1, 16, act);
void loadFileInternam(String^ fn)
{
}
我得到的错误:

错误:严重性代码 说明 项目文件行抑制状态 错误 C2665 'System::Threading::Tasks::Parallel::For':8 个都没有 重载可以转换所有参数 类型 ddddd C:\Users\Jack\Desktop 埃珀斯 ew_c++\文本编辑器 - 复制\CppCLR_WinformsProject1 - 复制 - 复制 - 复制(2) - 复制 (2)\Form1.h 1620

c# .net command-line-interface c++-cli
1个回答
0
投票
正如您在

here所看到的,Parallel::For

支持多种类型的
Action
,但不支持接受
String
参数的类型。

尚不清楚当

String

 调用 
loadFileInternam
 时,您真正想要的 
Parallel::For
 是什么。

您尚未提供任何上下文,但可以满足您需求的

Action

 类型可能是:
Action<Int32>
。这个 
Action
 将从您传递到 
Int32
 的范围内传递一个 
Parallel::For
:[1..16)。您可以使用此索引来选择要传递给 
loadFileInternam
 的相关字符串。

类似:

ref class Form1 { // The actual method yo uneed to invoke: void loadFileInternam(String ^ fn) { } // The Action used by Parallel::For (will be called for [1,16) in this case): void loadFileInternamHelper(Int32 idx) { String^ s = "aaa"; // determine s according to idx loadFileInternam(s); } void Run() { Action<Int32>^ act = gcnew Action<Int32>(this, &Form1::loadFileInternamHelper); System::Threading::Tasks::Parallel::For(1, 16, act); } };
    
© www.soinside.com 2019 - 2024. All rights reserved.