好吧,我下载了 Reactive Extensions for NET 3.5,以便在 Visual Studio 2008 中通过 c++/cli 使用它...
但所有任务并行库示例都是用 C# 编写的...我什至无法弄清楚将简单的 C# 语句转换为 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();
});
我如何在 C++/CLI 中编写这些语句?
最好的祝愿
#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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)