简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM