Question

Given that Invoke() blocks the calling thread until the delegate is executed, I was wondering if it is given any kind of priority over delegates queued by BeginInvoke(), which by definition would infer that timeliness is less important?

Anyone know? Yes, I could always whip up a test app but then I'm lazy ;-)

Was it helpful?

Solution

Dispatcher.Invoke() takes a DispatcherPriority as its first argument. That's a relatively crude priority arrangement. It otherwise functions as a FIFO queue, first come, first serve. Which all rather makes sense, priority can only be meaningful if the invoke queue is backed-up. A condition you want to avoid. And a rather nasty bug factory if it would work that way, code would execute in an unpredictable order depending on the machine speed and load.

OTHER TIPS

The only difference between the calls is that BeginInvoke is asynchronous whereas Invoke() is synchronous (as you point out). As far as I am aware, there is no preference to Invoke calls over BeginInvoke in the Dispatcher queue (assuming the same priority was used) but to prove this definitively, you could whip up that test app... :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top