> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SetEventOnCompletion

> Specifies an event that should be fired when the fence reaches a certain value. (ID3D12Fence.SetEventOnCompletion)

Specifies an event that's raised when the fence reaches a certain value.

## Syntax

```cpp theme={null}
HRESULT SetEventOnCompletion(
    UINT64 Value,
    HANDLE hEvent
)
```

### Parameters

*Value*\
Type: UINT64

The fence value when the event is to be signaled.

*hEvent*\
Type: HANDLE

A handle to the event object.

### Return value

Type: HRESULT

This method returns **E\_OUTOFMEMORY** if the kernel components don't have sufficient memory to store the event in a list. See [Direct3D 12 return codes](https://learn.microsoft.com/en-us/windows/win32/direct3d12/d3d12-graphics-reference-returnvalues) for other possible return values.

## Remarks

To specify multiple fences before an event is triggered, refer to [SetEventOnMultipleFenceCompletion](/reference/graphics/d3d12/interfaces/id3d12device1/methods/id3d12device1_seteventonmultiplefencecompletion_public).

If *hEvent* is a null handle, then this API will not return until the specified fence value(s) have been reached.

This method can be safely called from multiple threads at one time.

## Examples

The [D3D12Multithreading](https://learn.microsoft.com/en-us/windows/win32/direct3d12/working-samples) sample uses **ID3D12Fence::SetEventOnCompletion** as follows:

```cpp theme={null}
// Wait for the command list to execute; we are reusing the same command
// list in our main loop but for now, we just want to wait for setup to
// complete before continuing.

// Signal and increment the fence value.
const UINT64 fenceToWaitFor = m_fenceValue;
ThrowIfFailed(m_commandQueue->Signal(m_fence.Get(), fenceToWaitFor));
m_fenceValue++;

// Wait until the fence is completed.
ThrowIfFailed(m_fence->SetEventOnCompletion(fenceToWaitFor, m_fenceEvent));
WaitForSingleObject(m_fenceEvent, INFINITE);
```

Refer to the [Example code in the Direct3D 12 reference](https://learn.microsoft.com/en-us/windows/win32/direct3d12/notes-on-example-code).

## Requirements

**Header:** d3d12\_xs.h or d3d12\_x.h\
**Library:** d3d12\_xs.lib or d3d12\_x.lib\
**Supported Platforms**: XBOX Series consoles and XBOX One family

## See Also

[ID3D12Fence](/reference/graphics/d3d12/interfaces/id3d12fence/id3d12fence_public)

[Multi-engine synchronization](https://learn.microsoft.com/en-us/windows/win32/direct3d12/user-mode-heap-synchronization)


## Related topics

- [SetEventOnMultipleFenceCompletion](/reference/graphics/d3d12/interfaces/id3d12device1/methods/id3d12device1_seteventonmultiplefencecompletion_public.md)
- [DirectStorage Overview](/build/console-features/storage/directstorage/directstorage-overview.md)
- [GetDeviceRemovedReason](/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_getdeviceremovedreason_public.md)
- [Wait](/reference/graphics/d3d12/interfaces/id3d12commandqueue/methods/id3d12commandqueue_wait_public.md)
- [EventExportCompletionStatus](/services/playfab/api-references/events/data-types/eventexportcompletionstatus.md)
