我们可以 on/Off 监控 windows 8 中的时间间隔吗?

Can we turn on/Off monitor with respect to time intervals in windows 8?

我正在使用此代码关闭显示器,但我需要在某些情况下打开 off/on 显示器,例如晚上 6 点关掉它,晚上 7 点打开它,这可能吗?

    private int SC_MONITORPOWER = 0xF170;

    private uint WM_SYSCOMMAND = 0x0112;

    [System.Runtime.InteropServices.DllImport("user32.dll")]
    static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

    enum MonitorState
    {
        ON = -1,
        OFF = 2,
        STANDBY = 1
    }

    private void OnMonitor()
    {
        IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
        SendMessage(hwnd, WM_SYSCOMMAND, (IntPtr)SC_MONITORPOWER, (IntPtr)MonitorState.ON);
    }


    private void OffMonitor()
    {
        IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
        SendMessage(hwnd, WM_SYSCOMMAND, (IntPtr)SC_MONITORPOWER, (IntPtr)MonitorState.OFF);
    }

我不确定你的代码是否有效,但假设它有效,那么你可以使用某种计时器来实现这一点 假设您想在 6:00 下午关闭显示器然后

    System.Timers.Timer timer = new System.Timers.Timer();
    TimeSpan tsDifference = DateTime.Parse("06:00 pm").Subtract(DateTime.Now);
    timer.Interval= (double)((tsDifference.Hours * 60 * 60) + (tsDifference.Minutes * 60) + (tsDifference.Seconds)) * 1000 + (tsDifference.Milliseconds);    
    timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
    timer.Enabled=true;

      void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
            {
               //turn off your monitor
             }