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

# XDisplayAcquireTimeoutDeferral

> XDisplayAcquireTimeoutDeferral

# XDisplayAcquireTimeoutDeferral

取得螢幕逾時延遲。

## 語法

```cpp theme={null}
HRESULT XDisplayAcquireTimeoutDeferral(  
         XDisplayTimeoutDeferralHandle* handle  
)  
```

### 參數

*handle*   \_Out\_\
類型：XDisplayTimeoutDeferralHandle\*

指向螢幕逾時延遲之控制代碼的指標。

### 傳回值

類型：[HRESULT](https://learn.microsoft.com/openspecs/windows_protocols/ms-erref/0642cb2f-2075-4469-918c-4441e69c548a)

如果成功，則傳回 **S\_OK**；否則傳回錯誤碼。如需錯誤碼清單，請參閱[錯誤碼](/zh-TW/reference/errorcodes)。

## 備註

<Note>在時間敏感執行緒上呼叫此函式並不安全。如需詳細資訊，請參閱[時間敏感執行緒](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)。</Note>

螢幕逾時延遲可確保螢幕在使用者無動作期間不會變暗、鎖定或關閉電源。經過一定的閒置時間後，就會發生螢幕逾時。為回應螢幕逾時，裝置可能會將顯示器調暗、啟動鎖定畫面或關閉顯示器電源。發生螢幕逾時前所需的閒置時間取決於裝置的使用者設定。如果您的遊戲正在執行不需要使用者互動的活動 (例如載入遊戲資源或顯示較長的過場動畫)，螢幕逾時可能會造成不便。您可以透過取得螢幕逾時延遲來防止螢幕逾時。

若要取得螢幕逾時延遲，請先呼叫 **XDisplayAcquireTimeoutDeferral** 以取得螢幕逾時延遲的控制代碼，然後在不再需要控制代碼時呼叫 [XDisplayCloseTimeoutDeferralHandle](/zh-TW/reference/system/xdisplay/functions/xdisplayclosetimeoutdeferralhandle) 將其關閉。如果遊戲失去焦點，螢幕逾時延遲會被忽略；如果遊戲結束，螢幕逾時延遲則會被釋放。

<Note>如果您使用此函式取得螢幕逾時延遲控制代碼，就必須呼叫 **XDisplayCloseTimeoutDeferralHandle** 來關閉該控制代碼。可以取得多個螢幕逾時延遲控制代碼，而且只有在所有螢幕逾時延遲控制代碼都關閉之後，才會為遊戲啟用螢幕逾時。</Note>

<Note>在主動偵錯遊戲時，不會發生螢幕變暗。</Note>

下列範例會在呼叫 **XDisplayAcquireTimeoutDeferral** 取得新的螢幕逾時延遲控制代碼之後，播放一段較長的開場過場動畫。如果成功取得新的控制代碼，較長的開場過場動畫就可以播放，而不會因為使用者無動作而發生螢幕逾時。過場動畫播放完畢後，範例會呼叫 **XDisplayCloseTimeoutDeferralHandle** 來關閉控制代碼。所有螢幕逾時延遲控制代碼都關閉之後，就可能再次因為使用者無動作而發生螢幕逾時。

```cpp theme={null}
void Game::PlayIntroCutscene()
{
    XDisplayTimeoutDeferralHandle handle;

    // Try to acquire a new timeout deferral handle.
    if (SUCCEEDED(XDisplayAcquireTimeoutDeferral(&handle)))
    {
        // The newly-opened timeout deferral handle prevents the display
        // from dimming over the game if the user goes idle.
        // 
        // At this point, the long intro cutscene can play without dimmming.
    }

    // Once the cutscene has completed playing, 
    // close the timeout deferral handle.
    XDisplayCloseTimeoutDeferralHandle(handle);

    // If there are no open timeout deferral handles, the display can
    // once again dim over the game if the user goes idle.
}
```

## 需求

**標頭：** XDisplay.h

**程式庫：** xgameruntime.lib

**支援的平台：** Windows、XBOX One 系列主機和 XBOX Series 主機

## 概念文件

* [時間敏感執行緒](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## 另請參閱

[XDisplayCloseTimeoutDeferralHandle](/zh-TW/reference/system/xdisplay/functions/xdisplayclosetimeoutdeferralhandle)\
[XDisplay](/zh-TW/reference/system/xdisplay/xdisplay_members)


## Related topics

- [XDisplayAcquireTimeoutDeferral](/reference/system/xdisplay/functions/xdisplayacquiretimeoutdeferral.md)
- [XDisplay](/reference/system/xdisplay/xdisplay_members.md)
- [XDisplayCloseTimeoutDeferralHandle](/reference/system/xdisplay/functions/xdisplayclosetimeoutdeferralhandle.md)
