惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threatpost
Jina AI
Jina AI
S
SegmentFault 最新的问题
博客园 - 【当耐特】
阮一峰的网络日志
阮一峰的网络日志
IT之家
IT之家
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
aimingoo的专栏
aimingoo的专栏
博客园 - 叶小钗
The Cloudflare Blog
MyScale Blog
MyScale Blog
F
Full Disclosure
T
Tailwind CSS Blog
Recent Announcements
Recent Announcements
云风的 BLOG
云风的 BLOG
B
Blog
Apple Machine Learning Research
Apple Machine Learning Research
Engineering at Meta
Engineering at Meta
P
Privacy & Cybersecurity Law Blog
H
Help Net Security
A
Arctic Wolf
T
Tor Project blog
WordPress大学
WordPress大学
Cisco Talos Blog
Cisco Talos Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Project Zero
Project Zero
V2EX - 技术
V2EX - 技术
C
CERT Recently Published Vulnerability Notes
L
Lohrmann on Cybersecurity
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hacker News: Ask HN
Hacker News: Ask HN
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
S
Securelist
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 三生石上(FineUI控件)
PCI Perspectives
PCI Perspectives
雷峰网
雷峰网
J
Java Code Geeks
G
GRAHAM CLULEY
D
DataBreaches.Net
C
CXSECURITY Database RSS Feed - CXSecurity.com
Attack and Defense Labs
Attack and Defense Labs
美团技术团队
Security Archives - TechRepublic
Security Archives - TechRepublic
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
D
Docker
Cloudbric
Cloudbric
L
LangChain Blog

博客园 - answer

SQL查询重复记录 如何使用两台 NETGEAR 无线路由器进行无线中继(WDS) [转]取当前日期是在一年中的第几周 [转]写在UserControl销毁之时 给List排序( list sort) [转]检查本地DNS服务器是否正常工作及解决方法 SQLITE入门至精通 [转]string表达式运算 [转]HTC G11 ROOT获取权限教程 [转]WebForm 与 winform 路径获取 [转]win7 系统装SQLServer2000 成功。 Mobile Development: Disable Windows Mobile 6.5 Start and Close Button [转]Windows Mobile: Hide StartButton in WinMo 6.5.x Windows CE 电源管理(转贴) [转]分享8个超棒的免费高质量图标搜索引擎 [转]Win7系统下VS2005_2008不识别WinCE5 SDK [转]windows 7 下ASP.net 本地配置 ( IIS 7) [转]SQLite存取二进制数据 [转]SelectObject() 装载字体 VC EVC
[转]WM手机,关于如何让手机一直运行下去,而不进入待机
answer · 2012-03-20 · via 博客园 - answer

最近在WM手机上做一个水尺识别的项目,就是用手机不间断监测水库水位信息,把代码调差不多的时候,发现了一个问题,就是手机在拔掉USB线后运行程序,过一段时间手机会自动进入待机状态,导致CPU休眠,最后程序也就停止运行了.

首先看看MSDN的介绍吧:   http://msdn.microsoft.com/en-us/library/aa932196.aspx

这涉及到电源的管理方案.

刚开始我在注册表里找到

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\Timeouts

具体值如下:

从上面可以看出,在有AC电源的情况下, 60秒后会自动待机,在有电源的情况下也是60秒,这两个值都可以通过手机的电源管理上设置,也可以直接修改注册表.

我通过修改注册表的方法,把ACSuspendTimeOut 和BattSuspendTimerout值都设成零后,发现结果还是一样,程序还是会进入休眠状态。

最后通过调用下面的函数解决问题:

void KeepAlive()
{
SystemIdleTimerReset();
SHIdleTimerReset();
}

具体方法是通过一个定时器,定时的调用这个函数,就可以让程序保持非待机状态,最后完美的解决问题!

看看这两个函数在MSDN中的介绍吧:

SystemIdleTimerReset

This function resets a system timer that controls whether or not the device will automatically go into a suspended state.

void WINAPI SystemIdleTimerReset(void); 

Parameters

None.

Return Values

None.

Remarks

The default behavior is to go into a suspended state after a specified period of time expires. This time interval is specified in the registry. Calling SystemIdleTimerReset overrides the registry setting by resetting the timer.

If the Power Manager is managing timeouts, calls to SystemIdleTimerReset will still reset the GWES timeout and cause the screen saver to stop showing.

This function must be use appropriately. On battery powered devices, a program that never suspends (or sleeps) by continually calling SystemIdleTimerReset can quickly drain the batteries.

The frequency in which to call SystemIdleTimerReset in order to keep a device awake can be determined retrieving the following registry key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power

Requirements

OS Versions: Windows CE 2.0 and later.
Header: Winuser.h.

SHIdleTimerReset

This function prevents the shell from reverting to the Home screen and locking the device, when it is called periodically.

void WINAPI SHIdleTimerReset();

Parameters

None.

Return Values

None.

Remarks

To prevent the shell from reverting to the Home screen and locking the device, an application should call this function periodically. The minimum time-out that a user can specify in Settings is 10 seconds. Therefore, an application must call this function at least every 10 seconds to prevent the shell from reverting to the Home or Device lock. However, to conserve battery power, an application should call this function, on a timer, only while the user is performing operations. Otherwise, the application should allow the device to revert to Home or Device lock.

Requirements

Smartphone: Windows Mobile 2002 and later
OS Versions: Windows CE 3.0 and later
Header: tpcshell.h
Library: aygshell.lib

下面是在一个老外的网站看到的:

If you want your program to not be put to sleep while it's running, the best way is to create a KeepAlive type function that calls SystemIdleTimerReset, SHIdleTimerReset and simulates a key touch. Then you need to call it a lot, basically everywhere.

#include <windows.h> #include <commctrl.h> extern "C" { void WINAPI SHIdleTimerReset(); }; void KeepAlive() { static DWORD LastCallTime = 0;      DWORD TickCount = GetTickCount(); if ((TickCount - LastCallTime) > 1000 || TickCount < LastCallTime) // watch for wraparound { SystemIdleTimerReset(); SHIdleTimerReset();          keybd_event(VK_LBUTTON, 0, KEYEVENTF_SILENT, 0);          keybd_event(VK_LBUTTON, 0, KEYEVENTF_KEYUP | KEYEVENTF_SILENT, 0); LastCallTime = TickCount; } } 

This method only works when the user starts the application manually.

If your application is started by a notification (i.e. while the device is suspended), then you need to do more or else your application will be suspended after a very short period of time until the user powers the device out of suspended mode. To handle this you need to put the device into unattended power mode.

if(!::PowerPolicyNotify (PPN_UNATTENDEDMODE, TRUE)) { // handle error } // do long running process if(!::PowerPolicyNotify (PPN_UNATTENDEDMODE, FALSE)) { // handle error } 

During unattended mode use, you still need to call the KeepAlive a lot, you can use a separate thread that sleeps for x milliseconds and calls the keep alive funcation.

Please note that unattended mode does not bring it out of sleep mode, it puts the device in a weird half-awake state.

So if you start a unattended mode while the device in suspended mode, it will not wake up the screen or anything. All unattended mode does is stop WM from suspending your application. Also the other problem is that it does not work on all devices, some devices power management is not very good and it will suspend you anyway no matter what you do.

 转自:

http://hi.baidu.com/wangwenfang521/blog/item/a63236f3314c2cc60a46e0b5.html