在非表面设备中测试下面的代码工作正常,但是当我在表面上尝试时,只有在拔下电源线时才会收到通知(触发了“statusChange”powerMode)。将表面放入 SLEEP 处理程序中,它没有被调用('resume' 和 'suspend' powerModes 没有被触发)。
有谁知道为什么?谢谢你。

表面规范:
操作系统名称:Microsoft Windows 10 Pro
版本:10.0.17134 Compilação 17134
操作系统制造商:微软公司
系统制造商:微软公司
系统型号:Surface Pro
系统类型:基于 x64 的 PC
系统 SKU:Surface_Pro_1796

示例 [WPF Visual Studio Pro 2015]
主窗口:

using System;
using System.Windows;
using Microsoft.Win32;

namespace WpfApplication2
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            // SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(SystemEvents_PowerModeChanged);
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(SystemEvents_PowerModeChanged);
        }

        private void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
        {
            listView1.Items.Add(string.Format("{0} : Power mode changed = {1}", DateTime.Now, e.Mode));
        }
    }
}

XAML
<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplication2"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
    <Grid>
        <ListView x:Name="listView1" Margin="0">
            <ListView.View>
                <GridView>
                    <GridViewColumn/>
                </GridView>
            </ListView.View>
        </ListView>

    </Grid>
</Window>

最佳答案

我也在研究这样的问题。据我所知,Surface 支持“ sleep 状态(现代待机)”或 S0 低功耗,并且尚未处于实际 sleep 状态(S1-3)。按下电源按钮或单击 Windows 菜单中的“ sleep ”选项不会直接进入休眠,而是进入 S0 低功耗,因此不会触发 PowerModeChanged。

https://docs.microsoft.com/en-us/windows/desktop/power/system-power-states#sleep-state-modern-standby

10-08 08:17
查看更多