Colleagues,
Haven't dealt with Timer class "long, long ago in a language far, far away" (apologies, George!)
Wrote a function:
Here's the test code:
And here's the contents of that log file:
"2020-08-25 16:37:24: staring to test WaitNSeconds() function
2020-08-25 16:37:24: 1 iteration ended
2020-08-25 16:37:24: 2 iteration ended
2020-08-25 16:37:24: 3 iteration ended
2020-08-25 16:37:24: 4 iteration ended
2020-08-25 16:37:24: 5 iteration ended"
Evidently, the code in WaitNSeconds() ain't working.
What am I doing wrong?
Please advise.
TIA
Regards,
Ilya
Haven't dealt with Timer class "long, long ago in a language far, far away" (apologies, George!)
Wrote a function:
Code:
'===================================================================================================================================
Public Sub WaitNSeconds(Optional ByVal tiSeconds As Int32 = 0)
'===================================================================================================================================
' Purpose : Waits the given number of seconds.
' Description : Employs System.Timers.Timer object to count seconds.
' Parameters : Number of seconds to pause.
' Side effects : None.
' Notes : 1. Generic, applies to .NET Framework ver. 1.1, .NET Core 2.0, .NET Standard 2.0 and higher.
' 2. Silent.
' Revisions : 2020-08-25 by Ilya – started 1st draft.
'===================================================================================================================================
Dim loTimer As Timer = New Timer()
With loTimer
.Interval = (tiSeconds * 1000)
.AutoReset = False
.Enabled = True
End With
End Sub
'===================================================================================================================================
Here's the test code:
Code:
Dim lcLogStr As String = Now.ToString("yyyy-MM-dd HH:mm:ss") & ": staring to test WaitNSeconds() function" & vbCrLf
For liCnt As Int16 = 1 To 5
WaitNSeconds(2)
lcLogStr = lcLogStr & Now.ToString("yyyy-MM-dd HH:mm:ss") & ": " & liCnt.ToString() & " iteration ended" & vbCrLf
Next
Using loSW = New StreamWriter(gcLogFile, False)
loSW.Write(lcLogStr)
loSW.Flush()
End Using
End
And here's the contents of that log file:
"2020-08-25 16:37:24: staring to test WaitNSeconds() function
2020-08-25 16:37:24: 1 iteration ended
2020-08-25 16:37:24: 2 iteration ended
2020-08-25 16:37:24: 3 iteration ended
2020-08-25 16:37:24: 4 iteration ended
2020-08-25 16:37:24: 5 iteration ended"
Evidently, the code in WaitNSeconds() ain't working.
What am I doing wrong?
Please advise.
TIA
Regards,
Ilya