【问题标题】:Using .NET (3.5) Task Parallel Library in C++/ CLI在 C++/CLI 中使用 .NET (3.5) 任务并行库
【发布时间】:2011-01-20 09:56:47
【问题描述】:

好吧,我下载了 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 中编写这些语句?

最好的祝福

【问题讨论】:

  • 您好,托管 c++ 与 C# 有很大不同,您有使用 .NET 编写托管 c++ 应用程序的经验吗?
  • 不...正在学习...所以我问它... System.Action hola = () => Console.WriteLine("hola");许多特性在 C++/CLI 中不存在

标签: .net concurrency parallel-processing task


【解决方案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;
}

【讨论】:

    猜你喜欢
    • 2015-01-09
    • 2011-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-26
    • 2021-06-23
    • 1970-01-01
    • 2015-01-14
    相关资源
    最近更新 更多