Main Page » Blog-Like Typing Detected »

2015/07/30 - WPF annoyances, Part 2: Solution Here

Created:

Always use secure-HTTP / Secure HTTP / Permanent Link

Previously

At this point, I was fairly sure I was approaching this from the wrong angle. Shouldn't there be a way to accomplish this within the main thread? The answer, unfortunately, turned out to be an unqualified no. But there was still hope that I could still accomplish it in other ways!

Attempt 4: Dispatcher.BeginInvoke()

I know! I'll use the Dispatcher.BeginInvoke() method (every Dependency Object has a Dispatcher property from which I can access it), and apply that to attempt 2! This has the effect that 1. the action is executed in a different thread, and 2. said other thread is under the control of the Dependency Object, thus bypassing all the multithreading problems I mentioned in yesterday's po—

Result: The progress bar appears, then the window freezes until all the images are done loading. Which is to say no, it's still technically in the main thread.

Attempt 5: Lowering the temperature on Attempt 3

But wait! Dependency Objects can be frozen, which as the name implies, means that they cannot subsequently altered in any way. So I rebuilt attempt 3 from scratch because I'd irrevocably overwritten it with attempt 4 (d'oh), and this time I froze the loaded image.

Result: SUCCESS. The only hiccup is that it freezes at the end as it loads all the images into the main thread, but only for a split second. The cancel button even works just fine!

So, there you have it: it took a really obnoxious amount of time and effort, but it worked like a charm when I finally got it right!

Comments (auto-closed) (rss feed)

No comments on this article.