CNntpClient::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 NNTP_ERROR. To get extended error information, call GetLastError.

Remarks

When a client handle is created, it is associated with the current thread that created it. Normally, if another thread attempts to perform an operation using that handle, an error is returned since it does not own the handle. This is used to ensure that other threads cannot interfere with an operation being performed by the owner thread. In some cases, it may be desirable for one thread in a client application to create the client handle, and then pass that handle to another worker thread. The AttachThread method can be used to change the ownership of the handle to the new worker thread. By preserving the return value from the method, the original owner of the handle can be restored before the worker thread terminates.

This method should be called by the new thread immediately after it has been created, and if the new thread does not release the handle itself, the ownership of the handle should be restored to the parent thread before it terminates. Under no circumstances should AttachThread be used to forcibly release a handle allocated by another thread while a blocking operation is in progress. To cancel an operation, use the Cancel method and then release the handle after the blocking method exits and control is returned to the current thread.

Note that the dwThreadId parameter is presumed to be a valid thread ID and no checks are performed to ensure that the thread actually exists. Specifying an invalid thread ID will orphan the client handle used by the class 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: cstools11.h
Import Library: csnwsv11.lib

See Also

AttachHandle, Cancel, Connect, DetachHandle, Disconnect, GetHandle