简体   繁体   中英

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

UI tree:

  • listbox with the april 2010 toolkit's listboxdragdroptarget
  • listbox item template includes a control that has aa couple of buttons
  • the click handler in question is in one of those buttons (and therefore part of the actual listboxitem in the UI, so a potential drag-drop operation)
  • the overall listbox item should be able to drag (to rearrange within the listbox, or move to another listbox), but the goal is to keep the click handlers on these buttons from triggering a drag

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.

我认为DispatcherPriority低的Dispatcher.BeginInvoke的行为几乎类似于PostThreadMessage。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM