有关使用调度员优先级和绑定的建议

发布于 2024-12-05 07:10:49 字数 680 浏览 0 评论 0原文

在我的应用程序中,我使用 UI 线程的空闲时间来卸载昂贵的操作,如 有关 WPF 线程模型的 MSDN 文章

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

GenerateDate() 方法中,我访问 MSSQL 数据库、处理数据并更新视图模型上的绑定。自从实现此功能以来,我注意到一些绑定无法正确更新或根本无法更新。我已经检查了输出中是否存在绑定错误,并让第二个程序员确认了逻辑,还在依赖属性更改方法中设置了断点(断点不会被击中)。

是否有关于 which DispatcherPriority 的最佳实践建议(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);

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不在是我 2024-12-12 07:10:49

关于 WPF 调度程序的一篇非常好的文章: http ://weblogs.asp.net/pawanmishra/archive/2010/06/06/understanding-dispatcher-in-wpf.aspx

作为 WPF 程序员,我们可以将自定义的耗时逻辑推入
Dispatcher 类维护的队列并关联一个较低的
该工作项的优先级值。基于优先级字段的值
相应的代码将按照指定的时间间隔执行。
这里需要注意的重要一点是,所有工作仍在完成中
通过 UIthread,只是在 DispatcherPriority 的帮助下,我们
确定了我们任务的优先顺序。理想情况下建议优先
小于 7渲染)到我们希望的自定义​​逻辑
在 Dispatcher 的帮助下执行。最常见的优先值
Background 用于特定于应用程序的自定义逻辑。多发性硬化症
单词拼写检查就是借助该机制实现的
优先级值为 ApplicationIdle

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文