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

推荐订阅源

MongoDB | Blog
MongoDB | Blog
Recorded Future
Recorded Future
Jina AI
Jina AI
The Register - Security
The Register - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
F
Fortinet All Blogs
人人都是产品经理
人人都是产品经理
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
L
LangChain Blog
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
The GitHub Blog
The GitHub Blog
Vercel News
Vercel News
博客园 - 【当耐特】
雷峰网
雷峰网
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
aimingoo的专栏
aimingoo的专栏
云风的 BLOG
云风的 BLOG
I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
Security Latest
Security Latest
有赞技术团队
有赞技术团队
L
Lohrmann on Cybersecurity
P
Proofpoint News Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
P
Privacy & Cybersecurity Law Blog
Scott Helme
Scott Helme
Google Online Security Blog
Google Online Security Blog
WordPress大学
WordPress大学
Hacker News - Newest:
Hacker News - Newest: "LLM"
NISL@THU
NISL@THU
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
B
Blog RSS Feed
Cyberwarzone
Cyberwarzone
K
Kaspersky official blog
F
Full Disclosure
Martin Fowler
Martin Fowler
Spread Privacy
Spread Privacy
D
Docker
C
Cisco Blogs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
H
Hacker News: Front Page

博客园 - 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