在使用分派优先级和约束性建议 [英] Advice on using the Dispatcher Priority and Binding

查看:157
本文介绍了在使用分派优先级和约束性建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用我使用的UI线程的空闲时间通过的在WPF线程模型 MSDN文章。

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);

GenerateDate()方法我访问MSSQL数据库,过程中的数据,并更新绑定的视图模型。因为实现这一点,我已经注意到了一些的绑定无法更新正确或根本没有。我也检查输出装订错误,并有第二个程序员确认逻辑,还设置了依赖属性改变的方法中断点(断点没有得到命中)。

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).

有上的的任何最佳实践的建议的DispatcherPriority 链接到MSDN )时调用的动作包含绑定应该使用?

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

推荐答案

有关WPF调度员...的http://weblogs.asp.net/pawanmishra/archive/2010/06/06/understanding-dispatcher-in-wpf.aspx

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

作为一个WPF程序员,我们可以把我们的自定义的耗时将逻辑
  由调度员级和准较低的保持队列
  优先级值的工作项目。基于优先级字段的值
  相应的code将在指定时间间隔执行。
  这里要注意的重要的事情是,所有的工作仍然是正在做
  由UIthread,它只是与我们的DispatcherPriority的帮助
  有我们的优先任务。理想的情况是其建议优先
  值小于7(渲染)以我们希望的自定义​​逻辑
  与调度员的帮助下执行。大多数情况下的优先级值
  背景用于特定应用定制逻辑。女士
  单词拼写检查与此机制的帮助下实施,
  优先级为ApplicationIdeal。

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 "ApplicationIdeal".

这篇关于在使用分派优先级和约束性建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆