James Manning
James Manning

Reputation: 13579

silverlight 4 - fastest/simplest way of scheduling work on the UI thread?

UI tree:

Currently the click handler on one of the buttons (see above) appears to take long enough (it does a bunch of updates to the viewmodel, which cause various other UI changes, so it needs to be on the UI thread AFAICT) that it very often causes the drag event to start.

The first thought on getting this code out of the click handler is to create a BackgroundWorker with no DoWork and put it all in the RunWorkerCompleted. However, that feels like both an abuse of BackgroundWorker and kind of heavyweight. The effect I want is akin to just PostThreadMessage on the same thread (the UI thread) but I'm not seeing anything jump out at me for how to do so quickly.

I could certainly queue up something with the threadpool or even a new thread and then have it marshal it back over to the UI thread, but again that seems like quite the abuse.

Upvotes: 0

Views: 278

Answers (1)

Jens
Jens

Reputation: 25563

I think Dispatcher.BeginInvoke with a low DispatcherPriority behaves almost like PostThreadMessage.

Upvotes: 1

Related Questions