Question

I have a windows mobile 6.5 program which I want to trigger a call to a web server every ten minutes. But the event doesn't seem to be always being called. I have create a simple program to test when events are being triggered.

A threading.timer is set to execute every 10 seconds and then store the time in a string. I am trying to set a requirement for unattended mode so that this timer would continue to execute when the power button on the device is clicked or when the device is idle.

When I am clicking the power button on the device the timer stops executing.

Imports System.Threading
Imports Win32

Public Class Form1
    Dim time As String = ""
    Dim tmrUploadTimerThread As Timer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CoreDLL.PowerPolicyNotify(PPNMessage.PPN_UNATTENDEDMODE, -1)
        tmrUploadTimerThread = New Timer(New TimerCallback(AddressOf Timer_Worker), Nothing, 10000, 10000)
    End Sub

    Private Sub Timer_Worker()
        time = Now & Environment.NewLine & time
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = time
    End Sub

    Private Sub Form1_Closed(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Closed
        CoreDLL.PowerPolicyNotify(PPNMessage.PPN_UNATTENDEDMODE, 0)
        Me.Dispose()
        Application.Exit()
    End Sub

End Class

I got the class Win32 from Windows Mobile Power Management. Bellow is the code for PowerPolicyNotify:

[DllImport("CoreDLL")]
public static extern int PowerPolicyNotify(
      PPNMessage dwMessage,
      int option
//    DevicePowerFlags);
);
Was it helpful?

Solution

Timers and else is frozen when in suspend mode. Power modes are often mixed up. Your Unattended mode seems to be a Suspend Mode In Unattended mode, the display is shutoff but the system is still working processes etc. In suspend mode, the processes and threads are all frozen and only a hardware or timed event can wake up the device. The best is you use a Notification Event, these are also fired if the device is in suspend mode.

See here http://www.hjgode.de/wp/2011/12/23/windows-mobile-tasker2-runs-and-stops-applications-periodically/ and http://www.hjgode.de/wp/2009/07/14/howto-run-an-application-periodically/ and http://www.hjgode.de/wp/2013/05/13/mobile-development-manage-the-event-db-what-wakes-up-your-device/ for code samples in C++.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top