SetThreadDescription 函式 (processthreadsapi.h)

將描述指派給線程。

語法

HRESULT SetThreadDescription(
  [in] HANDLE hThread,
  [in] PCWSTR lpThreadDescription
);

參數

[in] hThread

您要設定描述之線程的句柄。 句柄必須具有THREAD_SET_LIMITED_INFORMATION存取權。

[in] lpThreadDescription

指定線程描述的 Unicode 字串。

傳回值

如果函式成功,則傳回值為代表成功作業的 HRESULT 。 如果函式失敗,傳回值為代表錯誤的 HRESULT

備註

線程的描述可以設定一次以上;會使用最近設定的值。 您可以呼叫 GetThreadDescription 來擷取線程的描述。

Windows Server 2016,Windows 10LTSB 2016Windows 10 1607 版:SetThreadDescription 僅適用於 KernelBase.dll 中的運行時間動態連結

範例

下列範例會將目前線程的描述設定為 simulation_thread

HRESULT hr = SetThreadDescription(GetCurrentThread(), L"simulation_thread");
if (FAILED(hr))
{
    // Call failed.
}

規格需求

需求
最低支援的用戶端 Windows 10 版本 1607 [傳統型應用程式 |UWP 應用程式]
最低支援的伺服器 Windows Server 2016 [傳統型應用程式 |UWP 應用程式]
目標平台 Windows
標頭 processthreadsapi.h
程式庫 Kernel32.lib
DLL Kernel32.dll

另請參閱

GetThreadDescription如何:在機器碼中設定線程名稱