> ## 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](/ja-jp/reference/graphics/d3d12/interfaces/id3d12device1/methods/id3d12device1_seteventonmultiplefencecompletion_public.md)
- [Wait](/ja-jp/reference/graphics/d3d12/interfaces/id3d12commandqueue/methods/id3d12commandqueue_wait_public.md)
- [DirectStorage の概要](/ja-jp/build/console-features/storage/directstorage/directstorage-overview.md)
- [GetDeviceRemovedReason](/ja-jp/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_getdeviceremovedreason_public.md)
- [EventExportCompletionStatus](/ja-jp/services/playfab/api-references/events/data-types/eventexportcompletionstatus.md)
