原因.NET UI元素的线程限制 [英] Reason for .Net UI Element Thread-restriction

查看:133
本文介绍了原因.NET UI元素的线程限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道,这是不可能执行code,从比元件被实例化的...我的问题是,为什么线程以外的任何线程操纵任何UI元素的属性?

We know that it is not possible to execute code that manipulates the properties of any UI element from any thread other than the thread the element was instantiated on... My question is why?

我还记得,当我们使用COM用户界面元素,(在COM / VB 6日),即用被称为线程局域的存储使用的内存模型的资源COM类和合作类创建的所有UI元素存储(TLS),但我记得,这是必需的,因为一些relaetd COM组件构建的方式,而不应是相关的.NET UI元素。世界卫生大会的原故这一限制仍然存在?是不是因为底层操作系统仍然采用基于COM的Win32 API的类所有UI元素,即使是那些操纵托管的.NET应用程序?

I remember that when we used COM user interface elements, (in COM/VB6 days), that all UI elements were created using COM classes and co-classes that stored their resources using a memory model referred to as Thread-Local-Storage (TLS) , but as I recall, this was required because of something relaetd to the way COM components were constructed, and should not be relevant to .Net UI elements. Wha's the underlying reason why this restriction still exists? Is it because the underlying Operating System still uses COM-based Win32 API classes for all UI elements, even the ones manipulated in a managed .Net application ??

推荐答案

AFAIK,它甚至比COM更基本。它去一直到好醇'的Windows API。我相信,在Windows窗口,预计一线,期间所拥有。每个线程都有它自己的消息泵,调度消息,它拥有的所有窗口。这是Windows的一项pretty的基本结构 - 也许有点过时,这些天,但基本

AFAIK, it's more basic than even COM. It goes right down to the good ol' Windows API. I believe that windows in Windows are expected to be owned by a thread, period. Each thread has it's own message pump, dispatching messages to the windows it owns. It's a pretty fundamental construct of Windows -- maybe a bit archaic these days, but fundamental.

我对它的感觉是,这个线程的亲和力有助于实现互操作性,当你需要整合到WPF Windows窗体应用程序,或者如果您需要猴与Windows对象别的地方在你的应用程序中使用,你有什么地方一个HWND ..它大概也就是允许老版本的Windows(XP)的主办WPF应用程序没有任何主要的架构改变操作系统本身。

My sense of it is that this thread affinity helps for interoperability when you need to integrate WPF into Windows Forms apps, or if you need to monkey with a Windows object somewhere else in your app using a HWND that you got somewhere... It probably also is what allows older versions of Windows (XP) to host WPF apps without any major architectural changes to the OS itself.

这篇关于原因.NET UI元素的线程限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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