ASP.NET和STA COM对象 [英] ASP.NET and STA COM objects
问题描述
我使用在VB中创建的COM对象从ASP.NET页面读取的所有东西都围绕着
警告 - 确认您在ASPCOMPAT上投放或无法运行
现在,我读这个
http://msdn.microsoft.com/en-us/library/zwk9h2kb.aspx
和
http://blogs.claritycon.com/blogs/don_peterson/archive/2008/01/17/3621.aspx p>
这表明你不会得到一个例外,它不会很好地工作。
此外,如果有任何方式,我可以在MTA和STA之间切换(通过一些调试器的魔法 - 甚至看着
/ div>
当然可以在ASP.NET应用程序中使用VB COM组件。你认为数百万行的VB代码不会在.NET-land中获得任何爱情? :)
VB COM组件使用单线程公寓(STA)编译是众所周知的 - 虽然不总是这样(如果我记得正确)。
在.NET中使用STA VB组件时,您可能会遇到以下情况:
- 可能的内存泄漏,由于封锁的终结者(不是试图一切都是厄运和阴暗,只是似乎发生更多的时候)损失
确定线程的MTA v。STA的简单方法是利用Windbg,连接到进程,加载SOS,执行!线程。您将看到类似的输出:
0:015> !threads
ThreadCount:27
UnstartedThread:0
BackgroundThread:17
PendingThread:0
DeadThread:10
Hosted运行时:no
PreEmptive GC分配锁
ID OSID ThreadOBJ状态GC上下文域计数APT异常
15 1 a28 000d75f0 1808220启用3823b58c:3823bb08 000d3fe8 0 STA(线程池工作者)
19 2 43c 000dd5f0 b220启用00000000:00000000 000d3fe8 0 MTA(Finalizer)
20 3 b94 000f20b0 80a220已启用00000000:00000000 000d3fe8 0 MTA(线程流完成端口)
21 4 15c 000f5318 1220已启用00000000:00000000 000d3fe8 0 Ukn
请注意,其中一个会话串在APT列中列出了STA。这个线程是一个STA线程,你可能看到你的VB COM代码在其调用堆栈。
参考讨论的问题:
- .NET互操作性在.NET Framework
- 运行ASMX服务STA主题
- 开发高性能ASP.NET网站
- STA组件引起的ASP.NET Hang和OutOfMemoryException
- Windows的调试工具
祝你好运!
Z
Looking to settle an argument here.
All the stuff I've read on using a COM object created in VB from an ASP.NET page is surrounding with
WARNING - MAKE SURE YOU PUT ON ASPCOMPAT OR IT WON'T WORK
However... I have set this up and guess what - no problems.
Now, I read this
http://msdn.microsoft.com/en-us/library/zwk9h2kb.aspx
and
http://blogs.claritycon.com/blogs/don_peterson/archive/2008/01/17/3621.aspx
Which suggests that you won't get an exception, it just won't work very well.
Could anyone give a definitive answer to what is going on?
Also, if there's any way that I could PROVE the switch between MTA and STA (through some debugger magic - even looking at the assembler!) I'd be grateful.
Cheers Duncan
Sure you can use a VB COM component in an ASP.NET application. You think that millions of lines of VB code aren't going to get any love in .NET-land? :)
VB COM components are notorious for being compiled using a Single Threaded Apartment (STA) - though not always the case (if I remember correctly).
When using a STA VB component in .NET you might find that you experience:
- Slower performance
- Possible memory leak due to blocked finalizer (not trying to be all doom and gloom, just seems to happen more often than not)
- Hair loss
An easy way to determine MTA v. STA for a thread is to leverage Windbg, connect to the process, load SOS, and execute !threads. You'll see output similar to:
0:015> !threads
ThreadCount: 27
UnstartedThread: 0
BackgroundThread: 17
PendingThread: 0
DeadThread: 10
Hosted Runtime: no
PreEmptive GC Alloc Lock
ID OSID ThreadOBJ State GC Context Domain Count APT Exception
15 1 a28 000d75f0 1808220 Enabled 3823b58c:3823bb08 000d3fe8 0 STA (Threadpool Worker)
19 2 43c 000dd5f0 b220 Enabled 00000000:00000000 000d3fe8 0 MTA (Finalizer)
20 3 b94 000f20b0 80a220 Enabled 00000000:00000000 000d3fe8 0 MTA (Threadpool Completion Port)
21 4 15c 000f5318 1220 Enabled 00000000:00000000 000d3fe8 0 Ukn
Note that one of threads has "STA" listed in the APT column. This thread is a STA thread and your likely to see your VB COM code on its call stack.
References discussing the problem:
- COM Interoperability in the .NET Framework
- Running ASMX services on STA Threads
- Developing High Performance ASP.NET Websites
- ASP.NET Hang and OutOfMemoryException caused by STA Components
- Debugging Tools for Windows
Good Luck!
Z
这篇关于ASP.NET和STA COM对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!