IWorkerThreadClient Interface

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at IWorkerThreadClient Interface.

IWorkerThreadClient` is the interface implemented by clients of the CWorkerThread class.

System_CAPS_ICON_important.jpg Important

This class and its members cannot be used in applications that execute in the Windows Runtime.

__interface IWorkerThreadClient

Methods

CloseHandleImplement this method to close the handle associated with this object.
ExecuteImplement this method to execute code when the handle associated with this object becomes signaled.

Implement this interface when you have code that needs to execute on a worker thread in response to a handle becoming signaled.

Header: atlutil.h

Implement this method to close the handle associated with this object.

HRESULT CloseHandle(HANDLE hHandle);

Parameters

hHandle
The handle to be closed.

Return Value

Return S_OK on success, or an error HRESULT on failure.

Remarks

The handle passed to this method was previously associated with this object by a call to CWorkerThread::AddHandle.

Example

The following code shows a simple implementation of IWorkerThreadClient::CloseHandle.

   HRESULT CloseHandle(HANDLE hObject)
   {
      // Users should do any shutdown operation required here.
      // Generally, this means just closing the handle.

      if (!::CloseHandle(hObject))
      {
         // Closing the handle failed for some reason.
         return AtlHresultFromLastError();
      }

      return S_OK;
   }

Implement this method to execute code when the handle associated with this object becomes signaled.

HRESULT Execute(DWORD_PTR dwParam, HANDLE hObject);

Parameters

dwParam
The user parameter.

hObject
The handle that has become signaled.

Return Value

Return S_OK on success, or an error HRESULT on failure.

Remarks

The handle and DWORD/pointer passed to this method were previously associated with this object by a call to CWorkerThread::AddHandle.

Example

The following code shows a simple implementation of IWorkerThreadClient::Execute.

   HRESULT Execute(DWORD_PTR dwParam, HANDLE hObject)
   {
      // Cast the parameter to its known type.
      LONG* pn = reinterpret_cast<LONG*>(dwParam);

      // Increment the LONG.
      LONG n = InterlockedIncrement(pn);

      // Log the results.
      printf_s("Handle 0x%08X incremented value to : %d\n", (DWORD_PTR)hObject, n);

      return S_OK;
   }

Classes
CWorkerThread Class

Show: