Need Help Shutting Down A .NET Windows Application Using A Timer
Posted on 2012-09-19
I am working on a VB.net program using Visual Studio 2008 and the .NET 3.5 Framework.
I have declared a timer object at the module level in the module containing my startup subroutine. The declaration is: Private WithEvents runmax As New Timer
In the startup module, I have the line: runmax.Interval = 300000
This is so I get a tick every 5 minutes.
I have code in the tick handler for runmax as follows:
Dim currentTime As TimeSpan = DateTime.Now.TimeOfDay
Dim shutdownTime As TimeSpan = New TimeSpan(7, 0, 0)
If currentTime > shutdownTime Then
'Need terminate code here
The system is form-less, so me.close() cannot be used to end the program after five hours of runtime. So, the question is: what do I put where it says "Need terminate code here"? The idea is that the run should end at 7:00 AM.
Windows Scheduler on Win 2008 R2 does have a maximum runtime setting, but it doesn't actually stop the run (i.e., there is a bug in Windows Scheduler on Win 2008). So I need to terminate the run after five hours of runtime. The scheduler properly starts the run at 2:00 AM as specified, but as stated the scheduler's maximum runtime setting does nothing.