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

الطرق

طريقةالوصف
Abort()يوقف الخيط. غير مُطبق.
get_CurrentCulture()يحصل على ثقافة الخيط.
static get_CurrentThread()يحصل على الكائن الذي يصف الخيط الحالي.
get_CurrentUICulture()يحصل على ثقافة واجهة المستخدم المستخدمة من قبل الخيط.
get_IsAlive()يتحقق مما إذا كان الخيط حيًا.
get_IsBackground()يتحقق مما إذا كان الخيط في الخلفية.
get_IsThreadPoolThread()يتحقق مما إذا كان الخيط مملوكًا من قبل مجموعة الخيوط.
get_ManagedThreadId() constيحصل على معرف الخيط. يمكن الحصول عليه من نظام التشغيل، ولكن إذا تجاوز معرف خيط نظام التشغيل حدود النوع int، قد تتقاطع معرّفات الخيوط.
get_Name()يحصل على اسم الخيط.
get_ThreadState()يحصل على حالة الخيط.
static GetCurrentThreadId()يحصل على معرف الخيط الحالي.
GetHashCode() const override
Interrupt()يقاطع الخيط. غير مُطبق.
Join()ينضم إلى الخيط المدار. ينفّذ انتظارًا غير محدود إذا لزم الأمر.
Join(int)ينضم إلى الخيط المدار. ينفّذ انتظارًا محدودًا.
Join(TimeSpan)ينضم إلى الخيط المدار. ينفّذ انتظارًا محدودًا.
static MemoryBarrier()يُزامن الوصول إلى الذاكرة.
operator=(const Thread&)ينسخ بيانات TLS من خيط مختلف.
set_CurrentCulture(const SharedPtr<Globalization::CultureInfo>&)يضبط ثقافة الخيط.
set_CurrentUICulture(const SharedPtr<Globalization::CultureInfo>&)يضبط ثقافة واجهة المستخدم المستخدمة من قبل الخيط.
set_IsBackground(bool)يضبط الخيط إلى الخلفية أو الواجهة.
set_Name(const System::String&)يضبط اسم الخيط.
static Sleep(int)يوقف الخيط الحالي للمهلة المحددة.
static Sleep(TimeSpan)يوقف الخيط الحالي للمهلة المحددة.
static SpinWait(int)ينتظر عددًا محددًا من تكرارات الحلقة.
Start()يبدأ الخيط باستخدام كائن حجة فارغ.
Start(const System::SharedPtr<System::Object>&)يبدأ الخيط.
Thread()منشئ.
Thread(ThreadStart)منشئ.
Thread(ParameterizedThreadStart)منشئ.
Thread(Thread&)منشئ النسخ.
static Yield()يُعطي الخيط فرصة التنفيذ.
virtual ~Thread()المدمر.

ملاحظات

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

انظر أيضًا