StartNew Task Action in C ++ / CLI

Is there a way to do the following in C ++ / CLI? (I think the answer is not due to lack of support for Action?)

public ref class MyClass { public: void TaskMethod(); void Start(); } void MyClass::Start() { Task^ myTask = Task::Factory->StartNew(??TaskMethod??); } 
+4
source share
1 answer

An action is just a delegate that is fully supported in C ++ / CLI. (Perhaps you confuse it with lambdas, which do not have support in C ++ / CLI.)

Here is the syntax for creating a delegate in C ++ / CLI.

 Task^ myTask = Task::Factory->StartNew(gcnew Action(this, &MyClass::TaskMethod)); // For non-static methods, specify the object. ^^^^ // Use the C++-style reference to a class method. ^^^^^^^^^^^^^^^^^^^^ 
+10
source

Source: https://habr.com/ru/post/1484686/


All Articles