OK. Since none of threading or tasking worked out for my case, I decided to make a little trick and use an animation to occupy UI thread and use its completed event handler to make the delay function for my application.
I made the following extension for the dispatcher first,
public static class Extensions
{
public static event EventHandler OnCompleted;
public static void WaitForFakeAnimation(this Dispatcher dispatcher, TimeSpan timeToWait, EventHandler onCompleted)
{
Storyboard sb = new Storyboard();
sb.Duration = timeToWait;
OnCompleted += onCompleted;
sb.Completed += (s,e) =>
{
OnCompleted(sb, null);
OnCompleted -= onCompleted;
};
sb.Begin();
}
}
I'm calling this from my GameManager class (which could be considered as a ViewModel)
EventHandler aferAnimation = (s,e) => {
lock (syncServiceUpdate)
{
AddNotification(notification);
// MessageBox.Show("after wait");
};
};
this.gamePage.Dispatcher.WaitForFakeAnimation(TimeSpan.FromSeconds(15), aferAnimation );
I would maybe send an ref Action to the extension as well but currently this solved my problem.
I hope this helps others as well.