Share via


DisplayRequest Classe

Définition

Représente une demande d’affichage.

public ref class DisplayRequest sealed
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.None)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.STA)]
class DisplayRequest final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.None)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.STA)]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
class DisplayRequest final
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.None)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.STA)]
public sealed class DisplayRequest
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.None)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.STA)]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
public sealed class DisplayRequest
function DisplayRequest()
Public NotInheritable Class DisplayRequest
Héritage
Object Platform::Object IInspectable DisplayRequest
Attributs

Configuration requise pour Windows

Famille d’appareils
Windows 10 (introduit dans 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduit dans v1.0)

Exemples

Le code suivant (extrait de l’exemple d’état d’alimentation d’affichage) montre comment activer, suivre et libérer les demandes d’affichage.

/// <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);
            }
        }
    }
}
''' <param name="sender"></param> 
''' <param name="e"></param> 
Private Sub Activate_Click(sender As Object, e As RoutedEventArgs) 
    ErrorTestBlock.Text = String.Empty 
    Dim b As Button = TryCast(sender, Button) 
    If b IsNot Nothing Then 
        Try 
            If g_DisplayRequest Is Nothing Then 
                ' This call creates an instance of the displayRequest object 
                g_DisplayRequest = New DisplayRequest() 
            End If 
        Catch ex As Exception 
            rootPage.NotifyUser("Error Creating Display Request: " & ex.Message, NotifyType.ErrorMessage) 
        End Try 

        If g_DisplayRequest IsNot Nothing Then 
            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 ex As Exception 
                rootPage.NotifyUser("Error:" & ex.Message, NotifyType.ErrorMessage) 
            End Try 
        End If 
    End If 
End Sub

''' <param name="sender"></param> 
''' <param name="e"></param> 
Private Sub Release_Click(sender As Object, e As RoutedEventArgs) 
    ErrorTestBlock.Text = String.Empty 
    Dim b As Button = TryCast(sender, Button) 
    If b IsNot Nothing Then 
        If g_DisplayRequest IsNot Nothing Then 
            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 ex As Exception 
                rootPage.NotifyUser("Error: " & ex.Message, NotifyType.ErrorMessage) 
            End Try 
        End If 
    End If 
End Sub 

Remarques

Pour économiser l’alimentation et prolonger l’autonomie de la batterie, le système réduit l’alimentation de l’ordinateur s’il ne détecte aucune activité de l’utilisateur pendant un certain temps. Selon les paramètres d’alimentation du système, l’affichage peut d’abord être grisé, un économiseur d’écran peut s’afficher et l’écran peut être désactivé à mesure que le système entre dans un état de veille à faible consommation d’énergie.

Les applications qui affichent des vidéos ou s’exécutent pendant des périodes prolongées sans intervention de l’utilisateur peuvent demander que l’affichage reste activé en appelant DisplayRequest.RequestActive. Lorsqu’une demande d’affichage est activée, l’affichage de l’appareil reste activé tant que l’application est visible. Lorsque l’utilisateur déplace l’application hors du premier plan, le système désactive les demandes d’affichage de l’application et les réactive lorsque l’application revient au premier plan.

Les demandes d’affichage sont cumulatives : chaque demande d’affichage doit être publiée avec un appel distinct à DisplayRequest.RequestRelease. Une application doit suivre le nombre de demandes d’affichage actives et s’assurer que toutes sont publiées (chacune avec un appel correspondant à DisplayRequest.RequestRelease) lorsque l’application n’a plus besoin que l’affichage reste allumé. Pour plus d’informations, consultez les pages suivantes :

L’utilisation des demandes d’affichage pour maintenir l’affichage allumé consomme beaucoup d’énergie. Suivez ces instructions pour optimiser le comportement de l’application lors de l’utilisation des demandes d’affichage.

  • Utilisez les demandes d’affichage uniquement si nécessaire, c’est-à-dire lorsque aucune entrée utilisateur n’est attendue, mais que l’affichage doit rester activé. Par exemple, lors de présentations en plein écran ou lorsque l’utilisateur lit un livre électronique.
  • Relâchez chaque demande d’affichage dès qu’elle n’est plus nécessaire.

Notes

Cette classe n’est pas agile, ce qui signifie que vous devez prendre en compte son modèle de thread et son comportement de marshaling. Pour plus d’informations, consultez Threading and Marshaling (C++/CX) et Using Windows Runtime objects in a multithreaded environment (.NET).

Windows Phone 8

Cette API est prise en charge uniquement dans les applications natives.

Constructeurs

DisplayRequest()

Crée une instance de la classe DisplayRequest.

Méthodes

RequestActive()

Active une demande d’affichage.

RequestRelease()

Désactive une demande d’affichage.

S’applique à