I have some code where I need to wait for an event to be fired but must timeout if it takes too long.
The way I am doing it at the moment is below. I set an Acknowledged flag to 0 and then loop until it is not 0.
It will be set to 1 in the event I am waiting for or -1 if the timer ticks. (the timer is disabled in the event so it doesn't fire after the event has happened)
Acknowledged and bkrtmr are both Public and declared in Process_Globals
This all seems to make sense but often I get the situation where the timer doesn't tick and I wait forever.
Is there a better way of doing this???
'in the start broker sub
'
Acknowledged = 0
brktmr.Initialize("brktmr", 2000)
brktmr.Enabled = True
Do While Acknowledged = 0
Sleep(50)
Loop
'at this point Acknowledged should be:
' 1 (from the client.connected event) or
' -1 from the brktmr_Tick event
'the Timer tick
Public Sub brktmr_Tick
brktmr.Enabled = False
Acknowledged = -1
End Sub
'The event
Public Sub Event
brktmr.Enabled = False
Acknowledged = 1
End Sub