2009-05-17 6 views
2

GPS 좌표를 기록하는 간단한 Windows Mobile 애플리케이션이 5 분마다 있습니다. 문제는 응용 프로그램이 작동하는 한 화면이 인 경우 대기 모드에서 응용 프로그램이 작동을 멈 추면 그대로 작동합니다. 기기를 켜면 앱이 다시 작동하기 시작합니다.Windows Mobile 앱을 대기 모드로 유지하십시오

대기 모드에서도 앱이 작동하도록하려면 어떻게해야합니까?

샌드위치

답변

4

CeRunAppAtTime 함수를 살펴보십시오. 명명 된 이벤트와 실행하려는 시간을 전달하십시오. 스레드에서 이벤트를 기다립니다. 일어나면 PowerPolicyNotify에 전화해야합니다. 그렇지 않으면 장치가 완료되기 전에 다시 일시 중단 될 수 있습니다.

코드처럼 보일 것이

CeRunAppAtTime(eventName,now + 5 minutes) 
while(!quit) 
WaitForSingleObject(event,timeout) 
PowerPolicyNotify(PPN_UNATTENDEDMODE,TRUE) 
DoGpsStuff() 
CeRunAppAtTime(eventName,now + 5 minutes) 
PowerPolicyNotify(PPN_UNATTENDEDMODE,FALSE) 
6

GPS와 나의 경험은 수정을 (적어도 내 장치에서) 얻을 수있는 시간이 걸립니다이다, 그래서 당신이에서 전화를 계속 생각 항상 정지 상태입니다. 내 장치로 놀고 있었을 때 화면이 꺼져있는 동안 내장 음악 플레이어를 사용하여 픽스를 가져와야한다는 것을 알았습니다. 래칫이 PowerPolicyNotify (PPN_UNATTENDEDMODE, TRUE)를 지적한 것처럼 "음악 플레이어 요구 사항"을 막는 올바른 방법 인 것 같습니다.

편집 : 일부 장치에서는 SetPowerRequirement/ReleasePowerRequirement를 사용해야하는 것처럼 보입니다.

public const int PPN_UNATTENDEDMODE = 0x0003; 
    public const int POWER_NAME = 0x00000001; 
    public const int POWER_FORCE = 0x00001000; 

    [DllImport("coredll.dll")] 
    public static extern bool PowerPolicyNotify(int dwMessage, bool dwData); 

    [DllImport("coredll.dll", SetLastError = true)] 
    public static extern IntPtr SetPowerRequirement(string pvDevice, CedevicePowerStateState deviceState, uint deviceFlags, string pvSystemState, ulong stateFlags); 

    [DllImport("coredll.dll", SetLastError = true)] 
    public static extern int ReleasePowerRequirement(IntPtr hPowerReq); 

    public enum CedevicePowerStateState : int 
    { 
     PwrDeviceUnspecified = -1, 
     D0 = 0, 
     D1, 
     D2, 
     D3, 
     D4, 
    } 

    //Keep the GPS and device alive: 
    PowerPolicyNotify(PPN_UNATTENDEDMODE, true) 
    IntPtr gpsPowerHandle = SetPowerRequirement("gpd0:", CedevicePowerStateState.D0, POWER_NAME | POWER_FORCE, null, 0); 

    //Call before exiting your app: 
    ReleasePowerRequirement(gpsPowerHandle); 
    PowerPolicyNotify(PPN_UNATTENDEDMODE, false); 
+0

웹에서 가장 확실한 답변입니다. 그것은 위대한 일을한다. 나는 그것이 wifi를 켜 놓는 것을 알아 차렸다. – GorillaApe

관련 문제