If possible, the preferred approach should be using an asynchronous way or a second thread.
If this isn't possible or wanted, using any implementation of DoEvents()
is a bad idea, since it may cause problems Possible problems with DoEvents. This is mostly about DoEvents with Winforms but the possible pitfalls in WPF are the same.
Then putting a frame on the Dispatcher with the wanted sleep time can be used:
using System;
using System.Threading;
using System.Windows.Threading;
public static void NonBlockingSleep(int timeInMilliseconds)
{
DispatcherFrame df = new DispatcherFrame();
new Thread((ThreadStart)(() =>
{
Thread.Sleep(TimeSpan.FromMilliseconds(timeInMilliseconds));
df.Continue = false;
})).Start();
Dispatcher.PushFrame(df);
}