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

# XPackageCloseInstallationMonitorHandle

> XPackageCloseInstallationMonitorHandle

# XPackageCloseInstallationMonitorHandle

以前に開かれた、指定されたインストール モニターを閉じます。

## Syntax

```cpp theme={null}
void XPackageCloseInstallationMonitorHandle(  
         XPackageInstallationMonitorHandle installationMonitor  
)  
```

### Parameters

*installationMonitor*   \_In\_\
型: XPackageInstallationMonitorHandle

閉じるインストール モニターへのハンドル。

### Return value

型: void

## Remarks

インストールの状態を監視するために使用したインストール モニターは、最終的に **XPackageCloseInstallationMonitorHandle** を呼び出して閉じる必要があります。

ゲームが起動マーカーを実装しているため、完全にインストールされる前に実行できます。ゲームは、どの部分がインストールされていて、どの部分がインストールされていないかを知る必要があります。この例では、指定されたトラック名を持つレーストラックに関連付けられたチャンクがいつインストールされるかを知る必要があります:

```cpp theme={null}
void CALLBACK ProgressChangedCallback( 
    void* /* context*/, XPackageInstallationMonitorHandle monitor) 
{ 
    XPackageInstallationProgress progress; 
    XPackageGetInstallationProgress(monitor, &progress); 
 
    if (progress.completed) 
    { 
        printf("Track ready\n"); 
        XPackageCloseInstallationMonitorHandle(monitor); 
    } 
} 
 
HRESULT StartMonitoring(XTaskQueueHandle queue, char* trackName) 
{ 
    char id[XPACKAGE_IDENTIFIER_MAX_LENGTH]; 
 
    HRESULT hr = XPackageGetCurrentProcessPackageIdentifier(_countof(id), id); 
    if (FAILED(hr)) return hr; 
 
    XPackageChunkSelector selector; 
    selector.type = XPackageChunkSelectorType::Tag; 
    selector.tag = trackName; 
 
    XPackageInstallationMonitorHandle monitor; 
    hr = XPackageCreateInstallationMonitor( 
        id,         // Identity to be monitored 
        1,          // Number of selectors 
        &selector,  // Selectors 
        1000,       // Resolution of the monitor, in milliseconds 
        queue,      // Queue where updates are performed 
        &monitor); 
    
    if (FAILED(hr)) return hr; 
 
    XTaskQueueRegistrationToken token; 
    hr = XPackageRegisterInstallationProgressChanged( 
        monitor, 
        nullptr, 
        ProgressChangedCallback, 
        &token); 
 
    if (FAILED(hr)) 
    { 
        XPackageCloseInstallationMonitorHandle(monitor); 
    } 
 
    return hr; 
} 
```

上記のコードの各 API 呼び出しを順に見ていきましょう:

```cpp theme={null}
XPackageGetCurrentProcessPackageIdentifier(_countof(id), id); 

```

インストールされたすべてのコンテンツには一意の識別子があります。パッケージ識別子を知っており、そのコンテンツにアクセス権があれば、任意のパッケージ インストールを監視できます。実行中のプロセスは自身のパッケージ識別子を取得できます。パッケージ識別子の詳細については、[ダウンロード可能なコンテンツ (DLC) の管理およびライセンス](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/fundamentals/xstore-manage-and-license-optional-packages) を参照してください。

```cpp theme={null}
XPackageCreateInstallationMonitor( 
    id,         // Identity to be monitored 
    1,          // Number of selectors 
    &selector,  // Selectors 
    1000,       // Resolution of the monitor, in milliseconds 
    queue,      // Queue where updates are performed 
    &monitor);  
```

これにより、インストールの状態を追跡するモニターが作成されます。このインストール モニターは、定期的なペースで自身を更新します。インストールの現在の進行状況を取得するには、[XPackageGetInstallationProgress](/reference/system/xpackage/functions/xpackagegetinstallationprogress) を呼び出します。インストール中の変更の通知を受けるには、コールバックを登録します。

パッケージ全体または特定のサブセットに対してインストール モニターを作成できます。ここでは、トラック名のインストール進行状況を知りたいと指定する「セレクター」を定義しています。インストール モニターが進捗状況のスナップショットを更新する頻度を指定できます (この場合は 1000 ms)。この速度が上限です。時間内に進行がなかった場合は、より遅くなる可能性があります。

```cpp theme={null}
HRESULT hr = XPackageRegisterInstallationProgressChanged( 
    monitor, 
    this, 
    ProgressChangedCallback,
    &token); 
```

トラックがいつロードを完了したかを知りたいので、モニターに進捗変更イベントを登録します。このコールバックは、モニターが作成されたときに提供されたタスク キューを通じて、[XPackageCreateInstallationMonitor](/reference/system/xpackage/functions/xpackagecreateinstallationmonitor) で指定されたおおよそのペースで呼び出されます。コールバック内で、ゲーム内の進捗を描画したり、トラックの準備が整ったことをゲームに通知したりできます。

この例では、インストール モニターを閉じますが、通知の登録は解除しません。インストール モニター通知のライフタイムはインストール モニターに結び付けられているため、モニターを閉じることで、それに関連するすべての通知が登録解除されます。

## Requirements

**ヘッダー:** XPackage.h

**ライブラリ:** xgameruntime.lib

**サポートされているプラットフォーム:** Windows、XBOX One ファミリー本体および XBOX Series 本体

## See also

[XPackage](/reference/system/xpackage/xpackage_members)


## Related topics

- [XPackageInstallChunks](/ja-jp/reference/system/xpackage/functions/xpackageinstallchunks.md)
- [XPackage](/ja-jp/reference/system/xpackage/xpackage_members.md)
- [GDK 向け Unity C# API ラッパー](/ja-jp/build/gdk-and-engines/unity/unity-api-wrappers.md)
- [XPackageUpdateInstallationMonitor](/ja-jp/reference/system/xpackage/functions/xpackageupdateinstallationmonitor.md)
- [XPackageCreateInstallationMonitor](/ja-jp/reference/system/xpackage/functions/xpackagecreateinstallationmonitor.md)
