What is wrong with this code? I am trying to write a sub that allows me to pause my code for the specified period of time. But when I run this it just sits in an infinite loop. I was expecting d to be static, but it keeps incrementing it’s value to ‘Now’ each time it is read AFAICT
Sub Sleep(DurationInSeconds as Integer)
Var di as New DateInterval
Var d as DateTime = DateTime.Now
Do Until di.Seconds > d.SecondsFrom1970 + DurationInSeconds
Me.Refresh
di.Seconds = d.SecondsFrom1970
Loop
End Sub
It’s a bad idea: not only will it lock up the program, the app will use 100% CPU, and on macOS you will get the beachball, and on Windows you’ll get the “This app has stopped responding” dialog.
The answer is to think about Event-driven programming, where you use Timers, Threads, etc. to accomplish the goal.
Can you say more about why you would want this Sleep() function in the first place?