2011-01-20 40 views
2

那麼使用.NET(3.5)任務並行庫,我下載無擴展的NET 3.5在Visual Studio 2008中使用C++中使用/ CLI ...在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的語句?

最良好的祝願

+0

嗨,託管C++是完全不同的從C#,你有使用.NET的寫作經驗託管C++應用程序? – 2011-01-20 09:59:25

回答

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