DisplayRequest Kelas
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mewakili permintaan tampilan.
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
- Warisan
- Atribut
Persyaratan Windows
Rangkaian perangkat |
Windows 10 (diperkenalkan dalam 10.0.10240.0)
|
API contract |
Windows.Foundation.UniversalApiContract (diperkenalkan dalam v1.0)
|
Contoh
Kode berikut (diambil dari sampel status daya tampilan) menunjukkan cara mengaktifkan, melacak, dan merilis permintaan tampilan.
/// <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
Keterangan
Untuk menghemat daya dan memperpanjang masa pakai baterai, sistem mengurangi daya ke komputer jika tidak mendeteksi aktivitas pengguna untuk waktu tertentu. Bergantung pada pengaturan daya sistem, tampilan dapat diredupkan terlebih dahulu, pengaman layar dapat ditampilkan, dan akhirnya tampilan dapat dimatikan saat sistem memasuki status tidur berdaya rendah.
Aplikasi yang menampilkan video atau berjalan untuk jangka waktu yang lama tanpa input pengguna dapat meminta agar tampilan tetap aktif dengan memanggil DisplayRequest.RequestActive. Saat permintaan tampilan diaktifkan, tampilan perangkat tetap menyala saat aplikasi terlihat. Saat pengguna memindahkan aplikasi dari latar depan, sistem menonaktifkan permintaan tampilan aplikasi dan mengaktifkannya kembali saat aplikasi kembali ke latar depan.
Permintaan tampilan bersifat kumulatif - setiap permintaan tampilan harus dirilis dengan panggilan terpisah ke DisplayRequest.RequestRelease. Aplikasi harus melacak jumlah permintaan tampilan aktif dan memastikan semua dirilis (masing-masing dengan panggilan yang sesuai ke DisplayRequest.RequestRelease) saat aplikasi tidak lagi mengharuskan tampilan tetap aktif. Untuk informasi selengkapnya, lihat:
Menggunakan permintaan tampilan untuk menjaga tampilan tetap aktif mengonsumsi banyak daya. Gunakan panduan ini untuk perilaku aplikasi terbaik saat menggunakan permintaan tampilan.
- Gunakan permintaan tampilan hanya jika diperlukan, yaitu, ketika tidak ada input pengguna yang diharapkan tetapi tampilan harus tetap menyala. Misalnya, selama presentasi layar penuh atau saat pengguna membaca e-book.
- Rilis setiap permintaan tampilan segera setelah tidak lagi diperlukan.
Catatan
Kelas ini tidak tangkas, yang berarti Anda perlu mempertimbangkan model utas dan perilaku marshalingnya. Untuk informasi selengkapnya, lihat Threading dan Marshaling (C++/CX) dan Menggunakan objek Windows Runtime di lingkungan multithreaded (.NET).
Windows Phone 8
API ini hanya didukung di aplikasi asli.
Konstruktor
DisplayRequest() |
Membuat instans kelas DisplayRequest . |
Metode
RequestActive() |
Mengaktifkan permintaan tampilan. |
RequestRelease() |
Menonaktifkan permintaan tampilan. |