0
잠자기 전에 장치가 대기하는 시간을 업데이트하는 데 사용하는 몇 가지 코드가 있습니다.OS에 전원 시간 제한 값을 레지스트리에서 다시로드하도록 알리십시오.
레지스트리를 업데이트 한 다음 값을 다시로드하도록 OS에 알려 주려고 시도하지만 작동하지 않습니다. (재로드 부분이 작동하지 않는 레지스트리가 잘 업데이트합니다..)
누군가 내가 뭘 잘못 알고있는 희망 내 코드를 게시 할 예정입니다 :
이// Change the amount of seconds that the OS will wait before it goes to sleep.
public void ChangeBatteryTimeout(int timeoutInSeconds)
{
// Attempt to open the key
RegistryKey key = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Power\\Timeouts", true) ??
// If the return value is null, the key doesn't exist, so create it.
Registry.LocalMachine.CreateSubKey("SYSTEM\\CurrentControlSet\\Control\\Power\\Timeouts");
if (key == null)
throw new KeyNotFoundException("Could not find or make the key for timeout manangment.");
// This value must be set for the timeout stuff to work.
// See:http://msdn.microsoft.com/en-us/library/aa932196.aspx
if (key.GetValue("ACUserIdle") == null)
key.SetValue("ACUserIdle", 0, RegistryValueKind.DWord);
// Set the Battery Suspend Timeout to be the passed in value.
key.SetValue("BattSuspendTimeout", timeoutInSeconds, RegistryValueKind.DWord);
// Signal the OS to reload the value we just changed.
DoAutoResetEvent();
}
// Tell to OS to reload the timeouts.
private static void DoAutoResetEvent()
{
const string eventString = "PowerManager/ReloadActivityTimeouts";
IntPtr newHandle = CreateEvent(IntPtr.Zero, false, false, eventString);
EventModify(newHandle, (int)EventFlags.EVENT_SET);
CloseHandle(newHandle);
}
private enum EventFlags
{
EVENT_PULSE = 1,EVENT_RESET = 2,EVENT_SET = 3
}
[DllImport("coredll.dll", SetLastError = true)]
private static extern IntPtr CreateEvent(IntPtr lpEventAttributes,
bool bManualReset, bool bInitialState, string lpName);
[DllImport("coredll")]
static extern bool EventModify(IntPtr hEvent, int func);
[DllImport("coredll.dll", SetLastError = true)]
private static extern bool CloseHandle(IntPtr hObject);
내가 ChangeBatteryTimeout(10);
와이 전화를하지만, 레지스트리가 변경되는 동안 장치는 10 초 안에 절전 모드가 해제되지 않습니다. (이전에 190 초로 설정 한 값을 사용합니다.)
도움이 될만한 의견이 있습니다.
플랫폼 빌더가 설치되었습니다. 하지만 최근의 하드 드라이브 충돌로 인해 다시 나에게 남겨졌습니다. 지금 설치 중입니다 ... 나는 WM_SETTINGCHANGE 메시지를 보냅니다. 다시 한번 감사드립니다! 당신은 모든 것 모바일의 구루입니다! – Vaccano
컨트롤 패널의 소스를 살펴 봤지만 배터리 관련 작업에 대한 WM_SETTINGCHANGED의 브로드 캐스트를 보지 못했습니다 (배경 만 업데이트하는 것을 볼 수 있습니다). SPI_SETBATTERYIDLETIMEOUT 또는 이와 유사한 것을 사용하여 뭔가를 볼 것으로 예상됩니다. 당신이보고있는 파일을 가르쳐 주시겠습니까? – Vaccano
전체 OS 버전 (Windows XP/무엇이든)에 대한 링크입니다. 이것은 Windows Mobile에 대한 링크입니다. http://msdn.microsoft.com/en-us/library/aa931802.aspx – Shaihi