I am using this code in a lot of places in my application and I know an alternative is using timers but that means I would have to add about 20 of them.. the issue with this is that if this is running and I close the app it hangs.. is there an alternative to use a function like this but with one timer instead?
Public Sub Delay_App(ByVal DelayInMilliseconds As Integer)
Dim ts As TimeSpan
Dim targetTime As DateTime = DateTime.Now.AddMilliseconds(DelayInMilliseconds)
Do
ts = targetTime.Subtract(DateTime.Now)
Application.DoEvents()
System.Threading.Thread.Sleep(50)
Loop While (ts.TotalSeconds > 0) AndAlso Application.OpenForms.Count > 0
End Sub