WdfWorkItemFlush function

[Applies to KMDF and UMDF]

The WdfWorkItemFlush method returns after a specified work item has been serviced.

Syntax

void WdfWorkItemFlush(
  WDFWORKITEM WorkItem
);

Parameters

WorkItem

A handle to a framework work-item object that is obtained from a previous call to WdfWorkItemCreate.

Return Value

None.

A bug check occurs if the driver supplies an invalid object handle.

Remarks

If your driver calls the WdfWorkItemFlush method, the method does not return until a system worker thread has removed the specified work item from the work-item queue and called the driver's EvtWorkItem callback function, and the EvtWorkItem callback function has subsequently returned after processing the work item.

Most drivers that use work items do not need to call WdfWorkItemFlush. A driver might call WdfWorkItemFlush if it must synchronize completion of work items with the removal of a remote I/O target. In this case, the driver can call WdfWorkItemFlush from within its EvtIoTargetQueryRemove callback function.

Note

It is legal to flush a workitem that is not enqueued and has never been enqueued.

For more information about work items, see Using Framework Work Items.

Examples

The following code example is an EvtIoTargetQueryRemove callback function from the Toaster sample driver.

NTSTATUS
ToastMon_EvtIoTargetQueryRemove(
    WDFIOTARGET IoTarget
)
{
    PTARGET_DEVICE_INFO  targetDeviceInfo = NULL;
    //
    // Get the I/O target object's context.
    //
    targetDeviceInfo = GetTargetDeviceInfo(IoTarget);
    //
    // Ensure that the I/O target's work item
    // has been processed before closing the target.
    //
    WdfWorkItemFlush(targetDeviceInfo->WorkItem);
    WdfIoTargetCloseForQueryRemove(IoTarget);

    return STATUS_SUCCESS;
}

Requirements

   
Target Platform Universal
Minimum KMDF version 1.0
Minimum UMDF version 2.0
Header wdfworkitem.h (include Wdf.h)
Library Wdf01000.sys (KMDF); WUDFx02000.dll (UMDF)
IRQL PASSIVE_LEVEL
DDI compliance rules DriverCreate, KmdfIrql, KmdfIrql2

See Also

EvtWorkItem