classe System::Threading::Thread

Thread class

Thread implementation. Objects of this class should only be allocated using System::MakeObject() function. Never create instance of this type on stack or using operator new, as it will result in runtime errors and/or assertion faults. Always wrap this class into System::SmartPtr pointer and use this pointer to pass it to functions as argument.

class Thread : public System::Object

Metodi

MetodoDescrizione
Abort()Interrompe il thread. Non implementato.
get_CurrentCulture()Ottiene la cultura del thread.
static get_CurrentThread()Ottiene l’oggetto che descrive il thread corrente.
get_CurrentUICulture()Ottiene la cultura dell’interfaccia utente usata dal thread.
get_IsAlive()Verifica se il thread è attivo.
get_IsBackground()Verifica se il thread è in background.
get_IsThreadPoolThread()Verifica se il thread è posseduto da un pool di thread.
get_ManagedThreadId() constOttiene l’identificatore del thread. Può essere ottenuto dal sistema operativo, ma se l’identificatore del thread del SO supera i limiti di int, gli ID dei thread possono sovrapporsi.
get_Name()Ottiene il nome del thread.
get_ThreadState()Ottiene lo stato del thread.
static GetCurrentThreadId()Ottiene l’identificatore del thread corrente.
GetHashCode() const override
Interrupt()Interrompe il thread. Non implementato.
Join()Unisce il thread gestito. Esegue un’attesa illimitata se necessario.
Join(int)Unisce il thread gestito. Esegue un’attesa limitata.
Join(TimeSpan)Unisce il thread gestito. Esegue un’attesa limitata.
static MemoryBarrier()Sincronizza l’accesso alla memoria.
operator=(const Thread&)Copia i dati TLS da un thread diverso.
set_CurrentCulture(const SharedPtr<Globalization::CultureInfo>&)Imposta la cultura del thread.
set_CurrentUICulture(const SharedPtr<Globalization::CultureInfo>&)Imposta la cultura dell’interfaccia utente usata dal thread.
set_IsBackground(bool)Imposta il thread in background o in primo piano.
set_Name(const System::String&)Imposta il nome del thread.
static Sleep(int)Ferma il thread corrente per il timeout specificato.
static Sleep(TimeSpan)Ferma il thread corrente per il timeout specificato.
static SpinWait(int)Attende un numero specifico di iterazioni del ciclo.
Start()Avvia il thread usando un oggetto argomento nullo.
Start(const System::SharedPtr<System::Object>&)Avvia il thread.
Thread()Costruttore.
Thread(ThreadStart)Costruttore.
Thread(ParameterizedThreadStart)Costruttore.
Thread(Thread&)Costruttore di copia.
static Yield()Restituisce thread.
virtual ~Thread()Distruttore.

Osservazioni

#include "system/threading/thread.h"
#include "system/smart_ptr.h"

int main()
{
  auto thread = System::MakeObject<System::Threading::Thread>([]()
  {
    std::cout << "Child thread ID: " << System::Threading::Thread::GetCurrentThreadId() << std::endl;
    System::Threading::Thread::Sleep(200);
  });

  std::cout << "Main thread ID: " << System::Threading::Thread::GetCurrentThreadId() << std::endl;

  thread->Start();
  thread->Join();

  return 0;
}
/*
This code example produces the following output:
Main thread ID: 2
Child thread ID: 1
*/

Vedi anche