嗯,我下载无扩展的NET 3.5使用它在Visual Studio 2008中使用C ++ / CLI ...
但是,所有任务并行库的例子是在C#中......我不能够找出即使转换是简单的C#语句转换为C ++ / CLI ...
//使用一个Action委托和指定的方法
任务任务1 =新的任务(新动作(printMessage));
//使用匿名委托
任务TASK2 =新任务(委托{
printMessage();
});
如何用C这些声明++ / CLI?
最良好的祝愿
解决方案 的#includestdafx.h中
#使用< System.Core.dll的>
使用命名空间系统;
使用命名空间系统:线程::任务;
引用类SomeTask {
上市:
静态INT的run(){
返回42;
}
};
INT主(数组<系统::字符串^> ^参数)
{
任务< INT> ^ =任务任务< INT> ::厂位于> StartNew(gcnew Func键< INT>(安培; SomeTask ::运行));
任务 - >等待();
控制台:的WriteLine(任务 - >结果);
返回0;
}
Well, I download Reactive Extensions for NET 3.5 to use it in visual studio 2008 with c++/cli...
But all Task Parallel Library examples are in C#...I can not able to figure out EVEN converting that simple C# statements into C++/ CLI...
// use an Action delegate and a named method
Task task1 = new Task(new Action(printMessage));
// use a anonymous delegate
Task task2 = new Task(delegate {
printMessage();
});
How can i write those statements in C++/CLI?
Best Wishes
解决方案#include "stdafx.h"
#using <System.Core.dll>
using namespace System;
using namespace System::Threading::Tasks;
ref class SomeTask {
public:
static int run() {
return 42;
}
};
int main(array<System::String ^> ^args)
{
Task<int>^ task = Task<int>::Factory->StartNew(gcnew Func<int>(&SomeTask::run));
task->Wait();
Console::WriteLine(task->Result);
return 0;
}