CLlmClient::AttachThread Method  
 
DWORD AttachThread(
  DWORD dwThreadId  
);

The AttachThread method attaches the specified client handle to another thread.

Parameters

dwThreadId
The ID of the thread that will become the new owner of the handle. A value of zero specifies that the current thread should become the owner of the client handle.

Return Value

If the method succeeds, the return value is the thread ID of the previous owner. If the method fails, the return value is LLM_ERROR. To get extended error information, call GetLastError.

Remarks

When a client handle is created, it is associated with the thread that created it. If another thread attempts to use the handle, the method will fail because that thread does not own the handle. This prevents other threads from interfering with an operation being performed by the owner thread. The AttachThread method changes the thread that owns the client handle. This is useful when one thread creates the client session and then passes it to a worker thread for processing. The method returns the thread ID of the previous owner, which can be saved and used later to restore ownership of the handle.

This method should normally be called by the new owner thread immediately after it has been created. If the worker thread does not release the handle itself, ownership should be restored to the original thread before the worker thread terminates. Do not use AttachThread to forcibly take ownership of a handle from another thread while a blocking operation is in progress. The handle should only be transferred when no other thread is actively using it.

The dwThreadId parameter is assumed to be a valid thread ID. This method does not verify that the specified thread exists. Specifying an invalid thread ID will orphan the handle until the destructor is called.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: csllmv12.lib

See Also