Disable sleep on the handheld terminal through a program

Source: Internet
Author: User

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
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.