Using .NET (3.5) Task Parallel Library in C++/ CLI

人盡茶涼 提交于 2019-12-12 17:27:34

问题


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


回答1:


#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;
}


来源:https://stackoverflow.com/questions/4745667/using-net-3-5-task-parallel-library-in-c-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!