How to create a Managed Thread in C ++ similar to the example in C #

4

In C # I use the following code to create the Managed Thread:

Thread thread = new Thread(new ThreadStart(minhaFuncao));

In C ++ I did:

using namespace System::Threading;
    .
    .
    Thread^ thread = gcnew Thread(gcnew ThreadStart(this,PutToSleep));

And when rebuilding, many errors end up being accused, only with those snippets of code.

How to make a managed thread in C ++ that works like the above code line in C #?

    
asked by anonymous 25.04.2014 / 14:17

1 answer

3

The error is on the line

  

Thread ^ thread = gcnew Thread (gcnew ThreadStart (this, PutToSleep));

In order to create the managed thread, the method pointer must be passed (the & operator is missing), and the method name must be fully qualified:

Thread^ thread = gcnew Thread(gcnew ThreadStart(&NOME_DA_CLASSE::NOME_DO_METODO));

As the example here on MSDN shows: Thread Class

    
25.04.2014 / 14:43