Advice on using the Dispatcher Priority and Binding

一曲冷凌霜 提交于 2019-12-23 17:35:57

问题


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?


回答1:


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 less then 7(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.



来源:https://stackoverflow.com/questions/7477039/advice-on-using-the-dispatcher-priority-and-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!