Imports System.Threading
Module mdlTimer
Private Timer As System.Threading.Timer = Nothing
Dim clsPathNames As frmPathNames
Public Sub StartTimer()
Dim intMinutessToStartOfTimer As Integer = GetMinutessToStartOfTimer()
Dim StartTime As New TimeSpan(0, intMinutessToStartOfTimer, 0)
Dim Interval As TimeSpan
Select Case strFrequency
Case "Once a Day"
Interval = New TimeSpan(1, 0, 0, 0) 'one day
Case "Even Few Hours"
Interval = New TimeSpan(byteIntervalTime, 0, 0) 'hours
Case "Every Few Days"
Interval = New TimeSpan(byteIntervalTime, 0, 0, 0) 'days
End Select
Timer = New System.Threading.Timer(New TimerCallback(AddressOf DeleteFiles), Nothing, StartTime, Interval)
End Sub
Public Function GetMinutessToStartOfTimer() As Integer
Const cMidnight As Integer = 24
Const cNoon As Integer = 12
Dim intCurrentHour As Integer = DatePart(DateInterval.Hour, Now)
Dim intHourInMinutes As Integer = intCurrentHour * 60
Dim intMinute As Integer = DatePart(DateInterval.Minute, Now)
Dim intMinutesToStartOfTimer As Integer = intMinute
Dim intStartTime As Integer = CInt(mdlManager.strStartTime.Remove(2)) '* trim ":00")
intStartTime = CInt(intStartTime)
If intStartTime = 0 Then intStartTime = cMidnight
If intStartTime < cNoon And intCurrentHour < cMidnight Then '* if start time delay crosses midnight
Dim intPreMidnightDelayHours As Integer = cMidnight - intCurrentHour
Dim intPreMidnightDelayMinutes As Integer = intMinute
Dim intPreMidnightDelay As Integer = (intPreMidnightDelayHours * 60) - intPreMidnightDelayMinutes
Dim intPostMidnightDelay As Integer = intStartTime * 60
intMinutesToStartOfTimer = intPostMidnightDelay + intPreMidnightDelay
Else
intMinutesToStartOfTimer = intHourInMinutes + intMinute
intMinutesToStartOfTimer = CLng((CInt(intStartTime) * 60) - intMinutesToStartOfTimer)
intMinutesToStartOfTimer = IIf(intMinutesToStartOfTimer >= 0, intMinutesToStartOfTimer, -intMinutesToStartOfTimer)
End If
Return intMinutesToStartOfTimer
End Function
Private Sub DeleteFiles(ByVal state As Object)
Console.WriteLine("Timer Callback: " & Now.ToString)
clsFilePaths.BuildFilePaths()
mdlManager.DeletedFiles()
End Sub
End Module
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE