我懷着極大的成功使用此之前:
Vb.net:
Imports System.Threading
Public Class AlarmClock
Public startTime As Integer = TimeOfDay.Hour
Public interval As Integer = 1
Public Event SoundAlarm()
Public Sub CheckTime()
While TimeOfDay.Hour < startTime + interval
Application.DoEvents()
End While
RaiseEvent SoundAlarm()
End Sub
Public Sub StartClock()
Dim clockthread As Thread = New Thread(AddressOf CheckTime)
clockthread.Start()
End Sub
End Class
C#:
using System.Threading;
public class AlarmClock
{
public int startTime = TimeOfDay.Hour;
public int interval = 1;
public event SoundAlarmEventHandler SoundAlarm;
public delegate void SoundAlarmEventHandler();
public void CheckTime()
{
while (TimeOfDay.Hour < startTime + interval) {
Application.DoEvents();
}
if (SoundAlarm != null) {
SoundAlarm();
}
}
public void StartClock()
{
Thread clockthread = new Thread(CheckTime);
clockthread.Start();
}
}
我不知道C#的作品,但是vb工作得很好。
使用在VB:
Dim clock As New AlarmClock
clock.interval = 1 'Interval is in hours, could easily convert to anything else
clock.StartClock()
然後,只需添加一個事件處理程序SoundAlarm事件。
你是否想要推出自己的Quartz.Net? http://ustznet.sourceforge.net/ –
@奧斯汀:不,我只是想找一個簡單的方法,就像我在最後一段描述的那樣,而不必自己推出或使用一些第三方組件。 – MusiGenesis
內置的Windows調度程序有一個可通過PInvoke訪問的API http://www.pinvoke.net/default.aspx/netapi32/NetScheduleJobAdd.html – xcud