TPL与InvokeRequired /调用 [英] TPL vs. InvokeRequired/Invoke

查看:124
本文介绍了TPL与InvokeRequired /调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于.NET 4.0有执行异步任务的第三方物流。如果你正在阅读的MSDN,所有的异步操作与交互形式/ UI依旧采用了InvokeRequire ...调用()模式。 我问的有是有原因的吧?从我了解到,太平人寿应该是某种替代旧的线程机制。那么什么是点忽略它时,它是关于UI线程? 关于有什么想法?

Since .NET 4.0 there is the TPL to execute asynchronous tasks. If you are reading the msdn, all async operations interacting with forms / UI still uses the InvokeRequire ... Invoke() pattern. What I'm asking is that is there a reason for it? From what I learned, TPL should be sort of a replacement of older threading mechanisms. So what's the point to ignore it when it's about UI threading? Any thoughts about that?

推荐答案

这似乎是相当主观的...

This seems fairly subjective...

当你说自.NET 4.0,你说在今年四月 - .NET已经存在了10年,现在,InvokeRequired /调用已被用于在过去9为什么会MS打破现有的所有UI code以任何理由?即使调用一个线程存在的一种新的方式,他们不能简单地改变模式,而不巨大的兼容性问题。

When you say "Since .NET 4.0", you are saying "as of April of this year" - .net has been around for 10 years now, and InvokeRequired/Invoke has been used for the last 9. Why would MS break all existing UI code for any reason? Even if a new way of calling to a thread existed, they could not simply modify the pattern without huge compatibility concerns.

此外,第三方物流是不是类似于InvokeRequired / Invoke的 - 第三方物流约为容易并行,并调用是关于一个的的具体的线程中运行code。我不知道为什么人们会取代其他,即使没有兼容性问题。

Also, the TPL is not analogous to InvokeRequired/Invoke - the TPL is about easy parallelism, and invoke is about running code on a specific thread. I'm not sure why one would replace the other even if there were no compatibility concerns.

请注意,没有什么的停止的您使用第三方物流,以确保您拨打的用户界面组件在正确的线程。事实上,你可以很容易地做到这一点。但是,这是由你和当前的API是不会的方式,是不是向后兼容改变。

Note that there is nothing stopping you from using the TPL to ensure you call UI components on the correct thread. In fact, you can easily do this. But that is up to you and the current API is not going to change in a way that isn't backwards compatible.

这篇关于TPL与InvokeRequired /调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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