- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 aspx 页面中,我调用了一个使用 STA 的 COM 组件。所以我使用 aspcompat=true 参数,但我想了解其中的逻辑。它到底做了什么?据我所知,在 STA 中,假定 仅由一个线程调用。所以我应该自己提供线程安全。
如果是这样,aspcompat 参数在哪里提供线程安全性?在整个页面上,还是仅在我访问 STA 组件的地方?
最佳答案
When using single-threaded apartment (STA) COM components, such as components developed using Visual Basic, from an ASP.NET page, you must include the compatibility attribute AspCompat=true in an
<%@ Page>
tag on the ASP.NET page
The AspCompat attribute forces the page to execute in STA mode
ASP.NET by default uses MTA (multi-threaded apartment) threads
When building ASP.NET applications that interface with old school COM objects like those created with VB6 or Visual FoxPro (MTDLL), it's extremely important that the threads that are serving requests use Single Threaded Apartment Threading. STA is a COM built-in technology that allows essentially single threaded components to operate reliably in a multi-threaded environment. STA's guarantee that COM objects instantiated on a specific thread stay on that specific thread and any access to a COM object from another thread automatically marshals that thread to the STA thread. The end effect is that you can have multiple threads, but a COM object instance lives on a fixed never changing thread.
ASP.NET by default uses MTA (multi-threaded apartment) threads which are truly free spinning threads that pay no heed to COM object marshaling. This is vastly more efficient than STA threading which has a bit of overhead in determining whether it's OK to run code on a given thread or whether some sort of thread/COM marshaling needs to occur. MTA COM components can be very efficient, but STA COM components in a multi-threaded environment always tend to have a fair amount of overhead.
ASP.NET 中的 STA
Support for STA threading in the ASP.NET framework is fairly limited. Specifically only the original ASP.NET WebForms technology supports STA threading directly via its STA Page Handler implementation or what you might know as ASPCOMPAT mode. For WebForms running STA components is as easy as specifying the ASPCOMPAT attribute in the @Page tag:
<%@ Page Language="C#" AspCompat="true" %>
which runs the page in STA mode. Removing it runs in MTA mode. Simple.
不支持 ASP.NET 技术的 STA
only WebForms supports STA natively
STA 组件令人头疼。我感觉到你的痛苦:-)
很好的引用:
关于.net - ASPX 页面中的 Aspcompat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5212334/
在我的 aspx 页面中,我调用了一个使用 STA 的 COM 组件。所以我使用 aspcompat=true 参数,但我想了解其中的逻辑。它到底做了什么?据我所知,在 STA 中,假定 仅由一个线程
我是一名优秀的程序员,十分优秀!