Applications on the handheld terminal need to connect to the server in real time, and the handheld device automatically jumps to sleep state after 5 minutes by default, although you can set the handheld device to never sleep in the advanced options of the device power, however, you must set it after each flash and never sleep when you do not run the program. This affects the battery life of the handheld terminal, you can call the system function to enable the handheld terminal to never sleep after the program is enabled. The Code is as follows:
[Csharp]
Using System. Runtime. InteropServices;
Using Microsoft. Win32;
[DllImport ("CoreDll. dll")]
Private static extern void SystemIdleTimerReset ();
Private static int ndisablesleepcils = 0;
Private static System. Threading. Timer preventSleepTimer = null;
Private static void PokeDeviceToKeepAwake (object extra)
{
Try
{
SystemIdleTimerReset (); // call the system function so that the system does not sleep
}
Catch (Exception e)
{
// TODO
}
}
/**/
/// <Summary>
/// </Summary>
Public static void DisableDeviceSleep ()
{
Ndisablesleepcils ++;
If (ndisablesleepcils = 1)
{
// Debug. Assert (preventSleepTimer = null );
PreventSleepTimer = new System. Threading. Timer
(New System. Threading. TimerCallback (PokeDeviceToKeepAwake ),
Null, zero, 30*1000 );
}
}
Private void FrmMain_Load (object sender, EventArgs e)
{
DisableDeviceSleep (); // enable the refresh thread when the program is created}
From # Define