Is there a synchronous wait function that won't tie up the UI-thread in .NET WPF? Something like:
Sub OnClick(sender As Object, e As MouseEventArgs) Handles button1.Click
Wait(2000)
'Ui still processes other events here
MessageBox.Show("Is has been 2 seconds since you clicked the button!")
End Sub
You can use a
DispatcherTimer
for that sort of thing.Edit: This might do as well...
(
Dispatcher.PushFrame
documentation.)Starting with .NET 4.5 you can use
async
event handlers andTask.Delay
to get the same behaviour. To simply let the UI update during such a handler returnDispatcher.Yield
.Here is a solution with
Task.Delay
. I'm using it in unit-tests forViewModel
s that useDispatcherTimer
.