> ## 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](/zh-TW/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](/zh-TW/reference/graphics/d3d12/interfaces/id3d12fence/id3d12fence_public)

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


## Related topics

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