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

## 另請參閱

[設計工作佇列](/zh-TW/build/core-features/common/async/async-task-queue-design)


## Related topics

- [PlayFab Multiplayer C++ SDK 版本資訊](/zh-TW/services/playfab/multiplayer/lobby/lobby-matchmaking-sdks/lobby-and-matchmaking-release-notes.md)
- [GDK 範例](/zh-TW/home/setup-install/samples.md)
- [PlayFab Party 版本資訊](/zh-TW/services/playfab/multiplayer/networking/release-notes.md)
- [GAMEPAD_REPORT structure](/zh-CN/reference/tools/xtf/xtfinput/structures/GAMEPAD_REPORT-xtfinput-xbox-windows-t.md)
- [异步 Lobby 和 Matchmaking C++ SDK 操作指南](/zh-CN/services/playfab/multiplayer/lobby/lobby-and-matchmaking-client-sdk-async.md)
