2

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

NoviceAndNovice
  • 705
  • 2
  • 13
  • 21

1 Answers1

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;
}
Mauro Sampietro
  • 2,739
  • 1
  • 24
  • 50