检测并防止/延迟Windows移动电源关闭

发布于 2024-08-23 14:43:39 字数 148 浏览 4 评论 0原文

我有一个窗口移动应用程序,需要在设备关闭之前检测电源关闭并执行一些操作。

我已经能够使用 RequestPowerNotifications win32 api 的 pinvoke 检测到设备正在关闭。

但是我不知道如何长时间关闭电源来运行我的代码。

I have a window mobile application which needs to detect power off and perform some operation before the device shuts down.

I have been able to detect that the device is shutting down using pinvoke to the RequestPowerNotifications win32 api.

However I can not figure out how to block the power off for long enough to run my code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ゝ偶尔ゞ 2024-08-30 14:43:39

作为一个应用程序,您无法阻止它,除非 OEM 以某种方式提供了一个自定义 API 来执行此操作(我从未在任何 WInMo 设备上见过它,只在一些自定义 CE 设备上见过它)。当电源管理器被告知暂停时,它会发出通知并立即开始关闭。唯一有机会延迟事情的子系统是驱动程序,并且它们在此期间无法调用 Win32 API(这意味着有机会关闭外设电源、保存寄存器等)。

我也不能说我见过任何应用程序这样做的充分理由。如果用户按下电源按钮,他们希望关闭电源,而不是被应用程序阻止。如果操作系统需要关闭电源(例如由于电量低),那么阻止它无论如何都是一件坏事。

As an application, you can't prevent it unless the OEM has somehow provided a custom API for doing so (and I've never seen it on any WInMo device, only on a few custom CE devices). Whent he power manager is told to suspend, it sends out the notification and begins shutdown immediately. The only subsystems that get an opportunity to delay things are drivers, and they can't call Win32 APIs during that time (it's meant as an opportunity to power off peripherals, save registers, etc).

I also can't say I've ever seen a good reason for an application to ever do this. If a user pushes the power button, they want to power down - not be inhibited by an app. If the OS needs to power down (like due to low power) then preventing it would be a bad thing anyway.

多像笑话 2024-08-30 14:43:39

正如 ctacke 指出的:这很脏。但是,只要电源通知线程指示设备正在尝试挂起,您就可以尝试 SetSystemPowerState( POWER_STATE_ON );

http://msdn.microsoft.com/en-us/library/ms920754.aspx

-PaulH

As ctacke pointed out: this is dirty. But, you could try SetSystemPowerState( POWER_STATE_ON ); whenever your power notification thread indicates the device is trying to suspend.

http://msdn.microsoft.com/en-us/library/ms920754.aspx

-PaulH

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文