> ## 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

> 指定当围栏达到某个值时应触发的事件。(ID3D12Fence.SetEventOnCompletion)

指定当围栏达到某个值时引发的事件。

## 语法

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

### 参数

*Value*\
类型：UINT64

发出事件信号时的围栏值。

*hEvent*\
类型：HANDLE

事件对象的句柄。

### 返回值

类型：HRESULT

如果内核组件没有足够的内存来将事件存储在列表中，则此方法返回 **E\_OUTOFMEMORY**。有关其他可能的返回值，请参阅 [Direct3D 12 返回代码](https://learn.microsoft.com/en-us/windows/win32/direct3d12/d3d12-graphics-reference-returnvalues)。

## 备注

要在触发事件之前指定多个围栏，请参阅 [SetEventOnMultipleFenceCompletion](/reference/graphics/d3d12/interfaces/id3d12device1/methods/id3d12device1_seteventonmultiplefencecompletion_public)。

如果 *hEvent* 为 null 句柄，则此 API 不会返回，直到达到指定的围栏值。

可以安全地从多个线程同时调用此方法。

## 示例

[D3D12Multithreading](https://learn.microsoft.com/en-us/windows/win32/direct3d12/working-samples) 示例按以下方式使用 **ID3D12Fence::SetEventOnCompletion**：

```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);
```

请参阅 [Direct3D 12 参考中的示例代码](https://learn.microsoft.com/en-us/windows/win32/direct3d12/notes-on-example-code)。

## 要求

**头文件：** d3d12\_xs.h 或 d3d12\_x.h\
**库：** d3d12\_xs.lib 或 d3d12\_x.lib\
**支持的平台**：XBOX Series 主机和 XBOX One 系列

## 另请参阅

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

[多引擎同步](https://learn.microsoft.com/en-us/windows/win32/direct3d12/user-mode-heap-synchronization)


## Related topics

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