此主题尚未评级 - 评价此主题

DisplayRequest Class

表示显示请求。

语法


public sealed class DisplayRequest : Object

特性

ActivatableAttribute(NTDDI_WIN8)
MarshalingBehaviorAttribute(None)
ThreadingAttribute(STA)
VersionAttribute(NTDDI_WIN8)

成员

DisplayRequest类 具有以下类型的成员:

构造函数

DisplayRequest类 具有以下构造函数。

构造函数描述
DisplayRequest Creates an instance of the DisplayRequest class.

 

方法

The DisplayRequest 类 具有以下方法。 使用 C#、Visual Basic 和 C++,它还可以继承以下内容中的方法 Object 类.

方法描述
RequestActive Activates a display request.
RequestRelease Deactivates a display request.

 

备注

为节约电量并延长电池寿命,系统会在一段时间未检测到任何用户活动的情况下减少对计算机的供电。根据系统电源设置,当系统进入低功率休眠状态时,会先显示为灰色,然后关闭。

显示视频或运行扩展期间而没有用户输入的应用程序可通过调用 DisplayRequest::RequestActive 请求保持显示。当激活显示请求时,当应用程序可见时设备显示保持。当用户将应用程序移除前景时,系统将停用应用程序的显示请求,并当应用程序返回给前景时重新激活它们。

显示请求是累积的 - 必须使用单独的对 DisplayRequest::RequestRelease 的调用释放每个显示请求。应用程序应跟踪活动显示请求的数目,并确保应用程序不再需要保留显示时释放所有请求(每个都带有对应 DisplayRequest::RequestRelease 的调用)。有关更多信息,请参见:

使用显示请求保留一个显示耗费大量的幂。在使用显示请求时,最好应用程序的行为请遵循以下准则。

  • 仅在需要时使用显示请求,也就是说,在没有预期的用户输入但显示应该保持的时间。例如,在全屏表示期间或用户阅读电子书籍时。
  • 释放每个不再需要的显示请求。
  • 当应用程序挂起时,释放所有显示请求。如果仍需要保持显示,则应用程序可以在重新激活时创建一个新的显示请求。

注意  此类不敏捷,这意味着您需要考虑其线程模型和封送行为。有关更多信息,请参见线程处理和封送处理 (C++/CX)在多线程环境中使用 Windows 运行时对象 (.NET)

示例

下面的代码(来自 显示电源状态示例)显示如何激活,跟踪和发布显示请求。



/// <param name="sender"></param> 
/// <param name="e"></param> 
private void Activate_Click(object sender, RoutedEventArgs e) 
{ 
    Error.Text = string.Empty; 
    Button b = sender as Button; 
    if (b != null) { 
        try { 
            if (g_DisplayRequest == null) { 
                // This call creates an instance of the displayRequest object 
                g_DisplayRequest = new DisplayRequest(); 
            } 
        } catch (Exception ex) { 
            rootPage.NotifyUser("Error Creating Display Request: " + ex.Message, NotifyType.ErrorMessage); 
        } 
 
        if (g_DisplayRequest != null) { 
            try { 
                // This call activates a display-required request. If successful,  
                // the screen is guaranteed not to turn off automatically due to user inactivity. 
                g_DisplayRequest.RequestActive(); 
                drCount += 1; 
                rootPage.NotifyUser("Display request activated (" + drCount + ")", NotifyType.StatusMessage); 
            } catch (Exception ex) { 
                rootPage.NotifyUser("Error: " + ex.Message, NotifyType.ErrorMessage); 
            } 
        } 
    } 
}

/// <param name="sender"></param> 
/// <param name="e"></param> 
private void Release_Click(object sender, RoutedEventArgs e) 
{ 
    Error.Text = string.Empty; 
    Button b = sender as Button; 
    if (b != null) { 
        if (g_DisplayRequest != null) { 
            try { 
                // This call de-activates the display-required request. If successful, the screen 
                // might be turned off automatically due to a user inactivity, depending on the 
                // power policy settings of the system. The requestRelease method throws an exception  
                // if it is called before a successful requestActive call on this object. 
                g_DisplayRequest.RequestRelease(); 
                drCount -= 1; 
                rootPage.NotifyUser("Display request released (" + drCount + ")", NotifyType.StatusMessage); 
            } catch (Exception ex) { 
                rootPage.NotifyUser("Error: " + ex.Message, NotifyType.ErrorMessage); 
            } 
        } 
    } 
} 

要求

最低受支持的客户端

Windows 8 [仅 Windows 应用商店应用]

最低受支持的服务器

Windows Server 2012 [仅 Windows 应用商店应用]

最低受支持的电话

Windows Phone 8

命名空间

Windows.System.Display
Windows::System::Display [C++]

元数据

Windows.winmd

 

 

本文是否对您有所帮助?
(1500 个剩余字符)
© 2013 Microsoft. 版权所有。