在 C# 中以编程方式输入连接待机 [英] Programmatically enter Connected Standby in C#
问题描述
所以似乎有很多问题询问如何在系统进入连接待机时检测,但我希望实际上导致它发生.
So it seems there are many questions asking how to detect when a system enters Connected Standby, but I'm looking to actually cause it to happen.
原因是,如果启用了连接待机(不会做任何糟糕的事情),并且我的应用程序将系统置于因此 sleep 不再有效.
Reason is, simply calling the SetPowerState(Sleep)
methods in C# no longer works if Connected Standby is enabled (doesn't do a darn thing whatsoever), and my app that puts the system to sleep therefore no longer works.
注意:我不想唤醒系统,我想做相当于点击开始 -> 电源 -> 睡眠.
Note: I don't want to wake up the system, I want to do the equivalent of clicking Start -> Power -> Sleep.
推荐答案
所以... 显然,因为当 S0 Low Power Idle 可用时没有Sleep",这就是传统方法让计算机进入睡眠状态的原因不起作用:该选项不可用.
So... Apparently, because there is no "Sleep" when S0 Low Power Idle is available, that is the reason traditional methods of putting a computer to sleep doesn't work: The option isn't available.
本质上,电源菜单中的睡眠命令只是关闭显示器,从而触发连接待机的其余部分.
Essentially, the Sleep command from the power menu simply turns off the display, which triggers the rest of Connected Standby.
因此,现有的用于关闭 Display 的代码将实现相同的效果,如下所示:
So, existing code to tell the Display off will achieve the same affect, something like so:
[DllImport("user32.dll")]
private static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);
void doStandby()
{
//Turn off the monitor
SendMessage(0xFFFF,0x112,0xF170,2);
}
当然,需要一些代码来确定哪种睡眠方法适合您的设备,但在别处讨论.
Of course, there needs to be some code to determine which sleep method is appropriate to your device, but that is discussed elsewhere.
这篇关于在 C# 中以编程方式输入连接待机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!