我有一个 windows mobile 6.5 程序,我想每十分钟触发一次对 Web 服务器的调用。但该事件似乎并不总是被调用。我创建了一个简单的程序来测试何时触发事件。
threading.timer 设置为每 10 秒执行一次,然后将时间存储在字符串中。我正在尝试设置无人值守模式的要求,以便在单击设备上的电源按钮或设备空闲时继续执行此计时器。
当我单击设备上的电源按钮时,计时器停止执行。
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
结束类
我从Windows Mobile Power Management获得了 Win32 类。下面是 PowerPolicyNotify 的代码:
[DllImport("CoreDLL")]
public static extern int PowerPolicyNotify(
PPNMessage dwMessage,
int option
// DevicePowerFlags);
);