简体   繁体   English

如何为经典ASP创建一个不会顺序阻止其他线程的DOTNET COM互操作程序集?

[英]How can I create a DOTNET COM interop assembly for Classic ASP that does not sequentially block other threads?

Setup -- Create a simple COM addin through DOTNET/C# that does nothing but sleep on the current thread for 5 seconds. 设置 - 通过DOTNET / C#创建一个简单的COM插件,它只会在当前线程上休眠5秒钟。

namespace ComTest
{
    [ComVisible(true)]
    [ProgId("ComTester.Tester")]
    [Guid("D4D0BF9C-C169-4e5f-B28B-AFA194B29340")]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    public class Tester 
    {
        [STAThread()]
        public string Test()
        {
            System.Threading.Thread.Sleep(5000); 
            return DateTime.Now.ToString();
        }

    }
}

From an ASP page, call the test component: 从ASP页面调用测试组件:

<%@ Language=VBScript %>
<%option explicit%>
<%response.Buffer=false%>

<%



 dim test
 set test = CreateObject("ComTester.Tester")


%>

 <HTML>
 <HEAD></HEAD>
 <BODY>
  <%
  Response.Write(test.Test())
  set test = nothing

  %>

 </BODY>
 </HTML>

When run on a windows 2003 server, the test.asp page blocks ALL OTHER threads in the site while the COM components sleeps. 在Windows 2003服务器上运行时,test.asp页面会在COM组件休眠时阻止站点中的所有其他线程。

How can I create a COM component for ASP that does not block all ASP worker threads? 如何为ASP创建一个不阻止所有ASP工作线程的COM组件?

I would say what is very likely happening here is that all web requests are getting serialized somewhere. 我想说这里发生的很可能是所有的Web请求都在某个地方被序列化了。 It is difficult tell exactly where this is happening, but there are a couple of possibilities. 很难准确地说出这种情况发生在哪里,但有几种可能性。

  • Your COM object lives in a single threaded apartment and is being shared between web requests somehow. 您的COM对象位于单线程单元中,并以某种方式在Web请求之间共享。 COM objects that live in an STA will have calls originating from threads other than the thread that created them marshalled onto the creating thread. 生活在STA中的COM对象将具有源自除创建它们的线程之外的线程的调用,这些线程被编组到创建线程上。 The effect is that callers from different threads must wait in line to execute Tester.Test . 结果是来自不同线程的调用者必须排队等待执行Tester.Test

  • The ASP requests are somehow being serialized. ASP请求以某种方式被序列化。 Based on my understanding of how ASP is suppose to work I am having difficulty envisioning how that would happen. 基于我对ASP如何工作的理解,我很难想象会发生什么。 Maybe you have an ASP.NET page with AspCompat set to true and that causes them to share the same apartment. 也许你有一个ASP.NET页面,AspCompat设置为true,这会导致他们共享同一个公寓。 I am really grasping here, but either way I would say your problem is related to the behavior of STA COM objects. 我真的很抓住这里,但无论如何我会说你的问题与STA COM对象的行为有关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 COM Interop(如何将数组传递给 com)通过经典 ASP - COM Interop (how to pass an array to the com) via classic ASP 如何为 COM 互操作库而不是程序集生成 C# 源代码? - How can I generate C# source code for a COM Interop library instead of an assembly? 如何在Classic ASP JScript中访问从CSharp COM对象返回的集合? - How can I access a collection returned from a CSharp COM object in Classic ASP JScript? COM / .NET互操作程序集可以与较新版本的COM组件一起使用吗? - Can a COM/.NET interop assembly be used with a newer version of the COM component? COM互操作:如何从LPDISPATCH获取CCW? - COM interop: How can I get the CCW from an LPDISPATCH? COM互操作是否尊重.NET AppDomain边界以进行程序集加载? - Does COM interop respect .NET AppDomain boundaries for assembly loading? 如何注册COM对象及其相关的Interop程序集? - How to register COM object and its associated Interop assembly? 经典的asp如何访问COM-Visible类引用的.NET dll? - How does classic asp access .NET dlls that are referenced by a COM-Visible class? 如何使用Interop COM在AutoCAD中更改块引用的颜色 - How to change Color of Block reference in autocad using interop COM 如何在没有互操作程序集的情况下创建Microsoft Jet(Access)数据库? - How do I create a Microsoft Jet (Access) database without an interop assembly?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM