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

Méthodes

MéthodeDescription
Abort()Interrompt le thread. Non implémenté.
get_CurrentCulture()Obtient la culture du thread.
static get_CurrentThread()Obtient l’objet qui décrit le thread actuel.
get_CurrentUICulture()Obtient la culture de l’interface utilisateur utilisée par le thread.
get_IsAlive()Vérifie si le thread est actif.
get_IsBackground()Vérifie si le thread est en arrière-plan.
get_IsThreadPoolThread()Vérifie si le thread appartient à un pool de threads.
get_ManagedThreadId() constObtient l’identifiant du thread. Il peut être récupéré auprès du système d’exploitation, mais si l’identifiant du thread OS dépasse les limites d’un int, les identifiants des threads peuvent se chevaucher.
get_Name()Obtient le nom du thread.
get_ThreadState()Obtient l’état du thread.
static GetCurrentThreadId()Obtient l’identifiant du thread actuel.
GetHashCode() const override
Interrupt()Interrompt le thread. Non implémenté.
Join()Joint le thread géré. Effectue une attente illimitée si nécessaire.
Join(int)Joint le thread géré. Effectue une attente limitée.
Join(TimeSpan)Joint le thread géré. Effectue une attente limitée.
static MemoryBarrier()Synchronise l’accès à la mémoire.
operator=(const Thread&)Copie les données TLS d’un autre thread.
set_CurrentCulture(const SharedPtr<Globalization::CultureInfo>&)Définit la culture du thread.
set_CurrentUICulture(const SharedPtr<Globalization::CultureInfo>&)Définit la culture de l’interface utilisateur utilisée par le thread.
set_IsBackground(bool)Définit le thread comme arrière-plan ou premier plan.
set_Name(const System::String&)Définit le nom du thread.
static Sleep(int)Arrête le thread actuel pendant le délai spécifié.
static Sleep(TimeSpan)Arrête le thread actuel pendant le délai spécifié.
static SpinWait(int)Attend un nombre spécifique d’itérations de boucle.
Start()Démarre le thread en utilisant un objet d’argument nul.
Start(const System::SharedPtr<System::Object>&)Démarre le thread.
Thread()Constructeur.
Thread(ThreadStart)Constructeur.
Thread(ParameterizedThreadStart)Constructeur.
Thread(Thread&)Constructeur de copie.
static Yield()Génère un thread.
virtual ~Thread()Destructeur.

Remarques

#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
*/

Voir aussi