Skip to main content
SetThreadInformation function

Sets information for the specified thread.


 BOOL  SetThreadInformation(
  _In_ HANDLE                   hThread,
  _In_ THREAD_INFORMATION_CLASS ThreadInformationClass,
       _In_reads_bytes_         ThreadInformation,
  _In_ DWORD                    ThreadInformationSize


hThread [in]

A handle to the thread. The handle must have THREAD_QUERY_INFORMATION access right. For more information, see Thread Security and Access Rights.

ThreadInformationClass [in]

The class of information to set. The only supported value is ThreadMemoryPriority.


Pointer to a structure that contains the type of information specified by the ThreadInformationClass parameter.

If the ThreadInformationClass parameter is ThreadMemoryPriority, this parameter must point to a MEMORY_PRIORITY_INFORMATION structure.

ThreadInformationSize [in]

The size in bytes of the structure specified by the ThreadInformation parameter.

If the ThreadInformationClass parameter is ThreadMemoryPriority, this parameter must be sizeof(MEMORY_PRIORITY_INFORMATION).

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.


To help improve system performance, applications should use the SetThreadInformation function with ThreadMemoryPriority to lower the memory priority of threads that perform background operations or access files and data that are not expected to be accessed again soon. For example, an anti-malware application might lower the priority of threads involved in scanning files.

Memory priority helps to determine how long pages remain in the working set of a process before they are trimmed. A thread's memory priority determines the minimum priority of the physical pages that are added to the process working set by that thread. When the memory manager trims the working set, it trims lower priority pages before higher priority pages. This improves overall system performance because higher priority pages are less likely to be trimmed from the working set and then trigger a page fault when they are accessed again.


The following example shows how to call SetThreadInformation with ThreadMemoryPriority to set low memory priority on the current thread.

DWORD ErrorCode;
    BOOL Success;

    // Set low memory priority on the current thread.

    ZeroMemory(&MemPrio, sizeof(MemPrio));
    MemPrio.MemoryPriority = MEMORY_PRIORITY_LOW;

    Success = SetThreadInformation(GetCurrentThread(),

    if (!Success) {
        ErrorCode = GetLastError();
        fprintf(stderr, "Set thread memory priority failed: %d\n", ErrorCode);
        goto cleanup;


Minimum supported client

Windows 8 [desktop apps only]

Minimum supported server

Windows Server 2012 [desktop apps only]


WinBase.h (include Windows.h)





See also