c++/cli 中的并行 for 循环

Parallel for loop in c++/cli

Parallel.For(<your starting value >,<End criteria for loop>, delegate(int < your variable Name>)
{
    // Your own code
}); 

我在上面展示了一些 C# 示例代码。我想要 C++/CLI 中的类似功能,但我不知道如何使用此表达式:"delegate(int < your variable Name>)".

如果您使用的是 c++cli,那么您应该能够使用与在 C# 中使用的相同的 Parallel.For,因为 System.Threading.Tasks.Parallel 是一个常规的 .Net 框架 class

示例(未经测试,甚至未编译):

ref class SomeClass  
{  
public:  
   static void Func(int index)  
   {  
      Console::WriteLine("Test {0}", index);  
   }  
};  

delegate void MyCallback(int index);  

int main( )   
{  
   MyCallback^ callback = gcnew MyCallback(SomeClass::Func);     
   Parallel.For(0, 9, callback);
}

相关:How to: Define and Use Delegates in C++/CLI