I want to do this without blocking the UI:
show_something_in_WPF()
wait_x_seconds()
show_something_else_in_WPF()
I know what you're thinking. Whatever you're waiting for, do it on another thread. You're an idiot. You don't understand async programming, etc.
Let me express the problem another way.
My application is a scripting host for a Python script. I am exposing a very minimal API to the user. In this application I am expecting the person who wrote the Python script to have very little programming experience; let alone understand threading. For example, this is a scriptlet:
images = [
"bunny.jpg", "chick.jpg", "dog.jpg", "ducky.jpg", "elephant.jpg",
"fox.jpg", "hamster.jpg", "husky.jpg", "kitten.jpg", "lemur.jpg",
"lizard.jpg", "lynx.jpg", "meercat.jpg", "monkey.jpg", "owl.jpg",
"penguin.jpg", "piglet.jpg", "polar-bear.jpg", "seal.jpg", "turtle.jpg"
]
for image in images:
imageView = ImageView('Cute\\images\\' + image)
mainRegion.Clear()
mainRegion.Add(imageView)
UI.Wait(5)
Since the scripting host is compiling and executing the script, I don't have the ability to intercept every line of code as it is executed (do I?) and consider if I should be awaiting the next line, set up threads etc.
The
UI.Wait(5)
that you see there does actually set up a timer, and queues up and chains timers, (and it works) but maintaining a timer essentially for every line of code is a huge undertaking, because I don't want the user to be limited to using only my API methods.
In Windows Forms there was the ugly hack to tell the UI thread to just shut up and do its thing for a while in
Application.DoEvents()
I've tried a few methods without much luck.
Any ideas on how to make a WPF application appear to run synchronously are welcome.
Meanwhile I'll dig around Scripting Host stuff to see if I can parse lines individually somehow.