检测并防止/延迟Windows移动电源关闭 [英] Detect and prevent/delay windows mobile power off

查看:243
本文介绍了检测并防止/延迟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移动电源关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆