I have a class that raises an event after a specified time (it uses a System.Timers.Timer inside). In my test code, I created a Stopwatch which I started before the class was created and set the callback for the event to stop that Stopwatch. Then, I blocked until Not Stopwatch.IsRunning. Simple, right?
My original blocking code was
While Stopwatch.IsRunning End While but I found that having an empty while loop like that never allowed my callback to fire! As soon as I put debugging code into the while loop, it worked!:
Dim lastSecond As Integer = 0 While sw.IsRunning If (Date.Now.Second > lastSecond) Then lastSecond = Date.Now.Second Console.WriteLine("blocking...") End If End While What causes this strange behavior, and more importantly, what's the simplest code I can put into my blocking section that will allow the event to fire?