DisplayRequest Classe

Definizione

Rappresenta una richiesta di visualizzazione.

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
Ereditarietà
Object Platform::Object IInspectable DisplayRequest
Attributi

Requisiti Windows

Famiglia di dispositivi
Windows 10 (è stato introdotto in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (è stato introdotto in v1.0)

Esempio

Il codice seguente (tratto dall'esempio di stato di alimentazione dello schermo) mostra come attivare, tenere traccia e rilasciare le richieste di visualizzazione.

/// <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 

Commenti

Per risparmiare energia ed estendere la durata della batteria, il sistema riduce l'alimentazione al computer se non rileva alcuna attività dell'utente per un determinato periodo di tempo. A seconda delle impostazioni di alimentazione del sistema, lo schermo può essere inizialmente disattivato, uno screen saver può essere visualizzato e alla fine lo schermo può essere disattivato quando il sistema entra in uno stato di sospensione a basso consumo.

Le app che mostrano video o vengono eseguite per periodi prolungati senza input dell'utente possono richiedere che la visualizzazione rimanga attiva chiamando DisplayRequest.RequestActive. Quando viene attivata una richiesta di visualizzazione, la visualizzazione del dispositivo rimane attiva mentre l'app è visibile. Quando l'utente sposta l'app in primo piano, il sistema disattiva le richieste di visualizzazione dell'app e li riattiva quando l'app torna in primo piano.

Le richieste di visualizzazione sono cumulative: ogni richiesta di visualizzazione deve essere rilasciata con una chiamata separata a DisplayRequest.RequestRelease. Un'app deve tenere traccia del numero di richieste di visualizzazione attive e assicurarsi che tutte vengano rilasciate (ognuna con una chiamata corrispondente a DisplayRequest.RequestRelease) quando l'app non richiede più che la visualizzazione rimanga attiva. Per altre informazioni, vedere:

L'uso delle richieste di visualizzazione per mantenere lo schermo su consuma molta potenza. Usare queste linee guida per un comportamento ottimale delle app quando si usano le richieste di visualizzazione.

  • Usare le richieste di visualizzazione solo quando richiesto, ovvero quando non è previsto alcun input dell'utente, ma la visualizzazione deve rimanere attiva. Ad esempio, durante le presentazioni a schermo intero o quando l'utente sta leggendo un e-book.
  • Rilasciare ogni richiesta di visualizzazione non appena non è più necessaria.

Nota

Questa classe non è agile, il che significa che è necessario considerare il modello di threading e il comportamento di marshalling. Per altre informazioni, vedere Threading e marshalling (C++/CX) e Uso di oggetti Windows Runtime in un ambiente multithreading (.NET).

Windows Phone 8

Questa API è supportata solo nelle app native.

Costruttori

DisplayRequest()

Crea un'istanza della classe DisplayRequest .

Metodi

RequestActive()

Attiva una richiesta di visualizzazione.

RequestRelease()

Disattiva una richiesta di visualizzazione.

Si applica a