Write a app that can suspend/resume device in specific time

  • Thread starter Thread starter wasishincar
  • Start date Start date
W

wasishincar

Hi there,

I'd like to write a program that can suspend ppc and resume it in 10
seconds. Here is what I'm doing, but it don't work. Please have some
comments if you know how to get device resume again. Thanks

Adam

// start of code
const int POWER_STATE_ON = 0x00010000;
const int POWER_STATE_OFF = 0x00020000;
const int POWER_STATE_SUSPEND = 0x00200000;
const int POWER_FORCE = 4096;

struct SYSTEMTIME
{
public ushort wYear;
public ushort wMonth;
public ushort wDayOfWeek;
public ushort wDay;
public ushort wHour;
public ushort wMinute;
public ushort wSecond;
public ushort wMilliseconds;
}

[DllImport("coredll.dll", EntryPoint = "CeRunAppAtTime", SetLastError
= true)]
private static extern bool CeRunAppAtTime(string pwszAppName, ref
SYSTEMTIME lpTime);

[DllImport("coredll.dll",
EntryPoint="SetSystemPowerState",SetLastError = true)]
private static extern int SetSystemPowerState(string psState, int
StateFlags, int Options);

static void Main(string[] args)
{
DateTime wakeuptime = new DateTime(DateTime.Now.Ticks);
wakeuptime = wakeuptime.AddSeconds(10.0);

SYSTEMTIME st = new SYSTEMTIME();
st.wYear = (ushort)wakeuptime.Year;
st.wMonth = (ushort)wakeuptime.Month;
st.wDay = (ushort)wakeuptime.Day;
st.wDayOfWeek = (ushort)wakeuptime.DayOfWeek;
st.wHour = (ushort)wakeuptime.Hour;
st.wMinute = (ushort)wakeuptime.Minute;
st.wSecond = (ushort)wakeuptime.Second;
st.wMilliseconds = (ushort)wakeuptime.Millisecond;

bool flag = CeRunAppAtTime("iexplore", ref st);

SetSystemPowerState(null, POWER_STATE_SUSPEND, POWER_FORCE);
}
// end of code
 
Back
Top