我怎样才能让程序在特定的时间自动运行(VB.NET)

我现在正在开发的应用程序允许用户每天更新一次Excel表格或Sql数据库以设置指标。 该程序通过在特定时间(例如上午6:00,下午5:00,下午3:42,无论用户设置)popup。 通过让程序在特定时间popup,程序(“Auto Excel It !!!”)允许您作为用户跟踪设置数据(例如销售电话,销售演示,会议,编码小时数,jalepeño数吃墨西哥卷饼等)。

开发人员如何通过Windows Scheduler API(或更好的方法)在特定的时间自动“popup”/启动/运行?

以下是我的理解最近的发展:

Nothing – >使用计时器作为程序在后台运行 – >使用Windows计划程序的API自动运行(当前) – >可能从您的答案重新理解

例如,我知道:DispatcherTimers,定时器,我不知道的另一个计时器,睡眠(),Windows调度程序。 但是考虑到这些因素,我不知道如何处理以下内容:通过Windows调度程序自动启动程序; 如果使用定时器,则保留计算机资源; 甚至如何让这个顶部自动popup。

更新1:

@ nfell2009:你的逻辑给了我很大的帮助。 起初,我不得不玩弄转换你的计时器在这里到一个DispatcherTimer(WPFforms的标准,似乎)。 然后,我将Sub tCheckTime的“Handles”切换为“AddHandler tCheckTime.Tick,AddressOf tCheckTime_Tick”—为什么我必须这样做才是一个好问题。

然后,一旦我设置了基本的EventHandlers,那么将用户的文本(​​As Date)与System.Date进行比较的想法是很好的 – 当我搞砸了一些东西,并且无法让代码工作的时候,我把它切换了并将System.Date转换为string – 即我从string – >datedate – >string …那是当我有计时器工作。 当我的System.Time勾选到3:12 PM时,MsgBoxpopup“Your Message Here”。

(一个快速(邪恶)谢谢!我花了四个多小时得到这个工作)

码:

从使用“处理”在tCheckTime_Tick(这似乎是'应该'工作)

Private Sub tCheckTime_Tick(sender As Object, e As EventArgs) Handles tCheckTime.Tick ... End Sub 

AddHandler等等,AddressOf tCheckTime_Tick(工作)

 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Loaded 'MsgBox(Now().ToString("hh:mm")) 'String.Format("{hh:mm}", Now())) AddHandler tCheckTime.Tick, AddressOf tCheckTime_Tick 'Why is this necessary? tCheckTime.Interval = New TimeSpan(0, 1, 0) End Sub 

 Public Class Form1 Dim iSetTime As Date Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub Private Sub btnSetTime_Click(sender As Object, e As EventArgs) Handles btnSetTime.Click If (tCheckTime.Enabled = True) Then tCheckTime.Enabled = False End If iSetTime = txtTHour.Text + ":" + txtTMinute.Text + ":" + txtTSecond.Text tCheckTime.Enabled = True End Sub Private Sub tCheckTime_Tick(sender As Object, e As EventArgs) Handles tCheckTime.Tick If (TimeOfDay = iSetTime) Then MsgBox("Your Message") End If End Sub End Class 

你将需要错误检查的文本框,但它只是:3文本框与指示哪个,所以也许标签每个与H,M,S – 或其他东西。

一个button,将设置时间和一个计时器。 命名:文本框小时= txtTHour

分钟= txtTMinute

秒= txtTSecond

button开始button= btnSetTime

定时器计时器= tCheckTime

我可以想到两个简单的方法:

  1. 让你的程序计算时间,直到接下来出现在秒内,然后设置一个计时器,这样当tick事件发生时,你可以做任何你需要做的事情。

  2. 使用MS任务pipe理器根据需要启动您的程序。