Private WithEvents tim As New System.Timers.Timer
Public Delegate Sub doSub()
Private thingToDo As doSub
Public Sub TimeOut(ByVal d As doSub, ByVal milliseconds As Integer)
thingToDo = d
tim.AutoReset = False
tim.Interval = milliseconds
tim.Start()
End Sub
Private Sub tim_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles tim.Elapsed
Invoke(thingToDo)
End Sub
Private Sub WBTimeOut()
Me.Finalize()
Me.Dispose()
End Sub
Here is an example. It is mostly working fine, but after it's dispose often I will get invoke error (not sure why) :/ (not sure why, sometimes it will work 100 times and sometimes it will fail on first disposale...
Is there any other better method to implement timeout ?