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

编程入门 行业动态 更新时间:2024-10-07 18:27:44
本文介绍了检测并防止/延迟Windows移动电源关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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.

推荐答案

作为应用程序,除非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.

更多推荐

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

本文发布于:2023-11-03 04:57:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554294.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:电源   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!