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);
);