Disabling the power key in windows mobile device

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?=

    Disabling the power key in windows mobile device

    Hi,
    I am trying to disable the power key in windows mobile version 6.0 while my
    application is running. The user should not be able to turn off or turn on
    the device. Those functionalities should happen by programming using C#
    codes. Could someone please help me with that? Is there any site that
    explains how to disable the power key on PDA device using C# codes?

    Thanks,
    Tammy


  • Peter Morris

    #2
    Re: Disabling the power key in windows mobile device

    public static class Device
    {
    [DllImport("Core Dll.dll")]
    public static extern void SystemIdleTimer Reset();

    private static int DisableSleepCal lsCount = 0;
    private static System.Threadin g.Timer PreventSleepTim er = null;


    public static void EnableDeviceSle ep()
    {
    DisableSleepCal lsCount--;
    if (DisableSleepCa llsCount == 0)
    {
    if (PreventSleepTi mer != null)
    {
    PreventSleepTim er.Dispose();
    PreventSleepTim er = null;
    }
    }
    }

    public static void DisableDeviceSl eep()
    {
    DisableSleepCal lsCount++;
    if (DisableSleepCa llsCount == 1)
    {
    TimerCallback keepAlive = new System.Threadin g.TimerCallback (
    delegate(object applicationData )
    {
    try
    {
    SystemIdleTimer Reset();
    }
    catch (Exception)
    {
    }
    }
    );
    PreventSleepTim er = new System.Threadin g.Timer(keepAli ve, null, 0, 30 *
    1000);
    }
    }
    }

    Not sure whether it disables the power key or not, but it stops it from
    going into sleep mode. I used to use it when importing lots of data.



    --
    Pete
    ====



    Comment

    • =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?=

      #3
      Re: Disabling the power key in windows mobile device


      Thank you so much for the codes. I used the codes however still am able to
      turn off/on the device by using powr button. I have to disable that button
      some how. I even used the registry key to power off and on the device but
      still I am able to intract with power button.

      "Peter Morris" wrote:
      public static class Device
      {
      [DllImport("Core Dll.dll")]
      public static extern void SystemIdleTimer Reset();
      >
      private static int DisableSleepCal lsCount = 0;
      private static System.Threadin g.Timer PreventSleepTim er = null;
      >
      >
      public static void EnableDeviceSle ep()
      {
      DisableSleepCal lsCount--;
      if (DisableSleepCa llsCount == 0)
      {
      if (PreventSleepTi mer != null)
      {
      PreventSleepTim er.Dispose();
      PreventSleepTim er = null;
      }
      }
      }
      >
      public static void DisableDeviceSl eep()
      {
      DisableSleepCal lsCount++;
      if (DisableSleepCa llsCount == 1)
      {
      TimerCallback keepAlive = new System.Threadin g.TimerCallback (
      delegate(object applicationData )
      {
      try
      {
      SystemIdleTimer Reset();
      }
      catch (Exception)
      {
      }
      }
      );
      PreventSleepTim er = new System.Threadin g.Timer(keepAli ve, null, 0, 30 *
      1000);
      }
      }
      }
      >
      Not sure whether it disables the power key or not, but it stops it from
      going into sleep mode. I used to use it when importing lots of data.
      >
      >
      >
      --
      Pete
      ====


      >
      >

      Comment

      Working...