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

# 方法: タスク キュー ハンドルの複製

> 方法: タスク キュー ハンドルの複製

## 例

長時間実行される作業がある場合は、その作業の期間中、タスク キュー ハンドルを複製したい場合があります。こうすると、`XTaskQueueCloseHandle` を呼び出す誰かが、まだキューを必要としている間にそれをクローズしてしまうことを防げます。これは次の例に示されています。

```c++ theme={null}
void DuplicatingTaskQueueHandle() 
{ 
    XTaskQueueHandle queue; 
 
    HRESULT hr = XTaskQueueCreate( 
        XTaskQueueDispatchMode::Manual,  
        XTaskQueueDispatchMode::Manual,  
        &queue); 
 
    if (FAILED(hr)) 
    { 
        printf("Failed to create task queue: 0x%x\r\n", hr); 
        return; 
    } 
 
    class LongRunningWork 
    { 
    public: 
        HRESULT Initialize(XTaskQueueHandle queue) 
        { 
            return XTaskQueueDuplicateHandle(queue, &m_queue); 
        } 
         
        ~LongRunningWork() 
        { 
            if (m_queue != nullptr) 
            { 
                XTaskQueueCloseHandle(m_queue); 
            } 
        } 
 
    private: 
        XTaskQueueHandle m_queue = nullptr; 
    }; 
 
    LongRunningWork work; 
    hr = work.Initialize(queue); 
     
    // Note that the queue handle for LongRunningWork is still valid. 
    XTaskQueueCloseHandle(queue); 
 
    if (FAILED(hr)) 
    { 
        printf("Failed to duplicate queue handle: 0x%x\r\n", hr); 
    } 
} 
```

## 関連項目

[タスク キューの設計](/build/core-features/common/async/async-task-queue-design)


## Related topics

- [SDK ライフサイクル](/ja-jp/services/playfab/sdks/c/lifecycle.md)
- [非同期タスク キューの設計](/ja-jp/build/core-features/common/async/async-task-queue-design.md)
- [方法: タスク キュー ウェイターの使用](/ja-jp/build/core-features/common/async/async-task-queue-design-howto/using-task-queue-waiter.md)
- [XTaskQueueDuplicateHandle](/ja-jp/reference/system/xtaskqueue/functions/xtaskqueueduplicatehandle.md)
- [タスク キューの作成例](/ja-jp/build/core-features/common/async/async-libraries/async-library-xtaskqueue-example-create-task-queue.md)
