定时提醒器框架
ActionBase.vb
Public MustInherit Class ActionBase Public Property Name As String Public MustOverride Function Start() As Boolean End Class
AlertAction.vb
Public Class AlertAction Inherits ActionBase Public Property MessageTitle As String = String.Empty Public Property MessageText As String = String.Empty Public Overrides Function Start() As Boolean MsgBox(Me.MessageText, MsgBoxStyle.OkOnly, Me.MessageTitle) Return True End Function End Class
ScheduleBase.vb
Public MustInherit Class ScheduleBase Public Property Name As String Public MustOverride Function GetNextTime() As Nullable(Of DateTime) Public MustOverride Sub Execute() Public Property BeginTime As Date = DateTime.Today Public Property EndTime As Date = DateTime.Today End Class
WeeklySchedule.vb
Imports System.Xml.Schema Public Class WeeklySchedule Inherits ScheduleBase Private weekList(7) As Boolean Public Overrides Function GetNextTime() As Nullable(Of DateTime) For i As Integer = 0 To 7 Dim destWeekDay As DateTime = DateTime.Now.AddDays(i) If Not weekList(destWeekDay.DayOfWeek) Then Continue For End If If destWeekDay.Date = DateTime.Today Then If DateTime.Now.TimeOfDay > ExecuteTime Then Continue For End If End If Return destWeekDay.Date.Add(ExecuteTime) Next Return Nothing End Function Public Overrides Sub Execute() If Not Me.Action Is Nothing Then Me.Action.Start() End If End Sub REM "Extension" Public Property ExecuteTime As TimeSpan Public Function GetWeekDayState(ByVal dayIndex As Integer) As Boolean Return weekList(dayIndex) End Function Public Sub SetWeekDayState(ByVal dayIndex As Integer, ByVal state As Boolean) weekList(dayIndex) = state End Sub Public Property Action As ActionBase End Class
frmMain.vb
Public Class frmMain Private Delegate Sub AsyncExecute() Private JobList As New List(Of ScheduleBase) Private Sub AddAWeeklyMeeting() Dim job As New WeeklySchedule job.Name = "QBE Weekly Meeting" job.ExecuteTime = New TimeSpan(13, 45, 0) Dim action = New AlertAction() action.MessageTitle = job.Name action.MessageText = "开会了" job.Action = action job.SetWeekDayState(3, True) '周三 job.SetWeekDayState(4, True) '周四 job.SetWeekDayState(5, True) '周五 JobList.Add(job) End Sub Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load AddAWeeklyMeeting() End Sub Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick For Each job As ScheduleBase In JobList If job.BeginTime > DateTime.Now.Date Or job.EndTime < DateTime.Now.Date Then Continue For End If Dim nextRunTime As Nullable(Of DateTime) = job.GetNextTime If nextRunTime Is Nothing Then Continue For End If Debug.Print(nextRunTime.ToString()) Dim nextTime As DateTime = nextRunTime.Value Dim currentTime As DateTime = DateTime.Now nextTime = New DateTime(nextTime.Year, nextTime.Month, nextTime.Day, nextTime.Hour, nextTime.Minute, nextTime.Second) currentTime = New DateTime(currentTime.Year, currentTime.Month, currentTime.Day, currentTime.Hour, currentTime.Minute, currentTime.Second) If nextTime <> currentTime Then Continue For End If Dim asyncMethod As AsyncExecute = New AsyncExecute(AddressOf job.Execute) asyncMethod.BeginInvoke(Nothing, Nothing) Next End Sub End Class
桂棹兮兰桨,击空明兮溯流光。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!