6128

Advice on using the Dispatcher Priority and Binding

In my application I'm using the idle-time of the UI thread to offload expensive operations as described by MSDN article on the WPF Threading Model.

GenerateDataAction = () => { GenerateData(); }; Dispatcher.BeginInvoke(GenerateDataAction, DispatcherPriority.Render, null);

In the GenerateDate() method I access an MSSQL database, process the data in, and update bindings on the viewmodel. I have noticed since implementing this that some binding fail to update properly or not at all. I have check the output for binding errors and had a second programmer confirm the logic, also have set breakpoints within the dependency property changed method (the breakpoints do not get hit).

Is there any best-practice advice on which DispatcherPriority (link to MSDN) should be used when the invoked action contains bindings?

Answer1:

A very good article about WPF dispatcher: http://weblogs.asp.net/pawanmishra/archive/2010/06/06/understanding-dispatcher-in-wpf.aspx

As a WPF programmer, we can push our custom time consuming logic into the queue maintained by the Dispatcher class and associate a lower priority value to that work item. Based on the value of priority field the corresponding code will be executed at the specified interval. Important thing to note here is that all the work is still being done by the UIthread, its just that with the help of DispatcherPriority we have prioritized our tasks. Ideally its recommended to give priority values <strong>less then 7</strong>(Render) to the custom logic that we wish to execute with the help of Dispatcher. Most often priority value Background is used for application specific custom logic. MS Word spell check is implemented with the help of this mechanism and priority value is ApplicationIdle.

Recommend

  • How to select parent ids
  • How to setup a reverse proxy on several ports (tcp & udp)
  • Passing Query Parameters from HTML/JS App to Azure Server Script
  • _Layout.cshtml cannot be requested directly because it calls the “RenderBody” method
  • Cannot convert value of type 'X' to expected argument type 'X'
  • What is the best data type to store boolean values in a database
  • Simple Factory with reflection C#
  • Build Matrix of Comparisons in SQl Server
  • How to override jQuery promise callback
  • Should I be afraid to use UDP to make a client/server broadcast talk?
  • How do I translate LR(1) Parse into a Abstract syntax tree?
  • Regex for nested values
  • Lua: Line breaks in strings
  • A class implementing two different IObservables?
  • VBA Excel, loop through variables
  • Consuming a WCF service in a Java Client using wsHttpBinding
  • Knockout custom binding handler
  • converter json to two dimensional array
  • Creating a DropDownList
  • Is there a way to save the selected text and highlight it again once the page is refreshed?
  • Git describe fails to return most recent annotated tag
  • Force show.bind execution
  • Firefox Extension - Monitor refresh and change of tab
  • How can I sort a a table with VBA with given text condition?
  • D3 nodes and links from JSON with nested arrays of children
  • Get one-time binding to work for ng-if
  • Pass value from viewmodel to script in zk
  • jQuery show() function is not executed in Safari if submit handler returns true
  • How to extract text from Word files using C#?
  • How to check if every primary key value is being referenced as foreign key in another table
  • Sending data from AppleScript to FileMaker records
  • QuartzCore.framework for Mono Develop
  • How to format a variable of double type
  • Understanding cpu registers
  • How do I configure my settings file to work with unit tests?
  • Java static initializers and reflection
  • How to get Windows thread pool to call class member function?
  • Is there any way to bind data to data.frame by some index?
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How do I use LINQ to get all the Items that have a particular SubItem?