ASP.NET会话和存储使用对象的COM互操作 [英] ASP.NET session and storing objects that use COM interop

查看:143
本文介绍了ASP.NET会话和存储使用对象的COM互操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个asp.net网站。我们必须使用COM互操作与传统VB6 ActiveX组件进行交互。在许多情况下,组件依赖于接收的上下文对象(其本身是一个vb6的ActiveX组件)作为参数。上下文对象是相当昂贵的构建。

I'm working on an asp.net web site. We have to use com interop to interact with legacy vb6 activex components. The components in many cases rely on receiving a context object (which is itself a vb6 activex component) as a parameter. The context object is fairly costly to construct.

因此​​,人们的想法是,上下文对象被构造一次并存储在asp.net会话。但是,如果此对象只是围绕一个ActiveX组件一个.NET包装,是明智还是advisible会话坚持这样一个对象?

Therefore one idea is that a context object is constructed once and stored in asp.net session. However, if this object is just a .net wrapper around an activex component, is it wise or advisible to persist such an object in session?

此外上下文对象包含用户特定的信息,使用达的httpRuntime缓存可以使用如此持续,但需要一个用户特定的密钥。

Additionally the context object contains user specific information, so persisting using .net HttpRuntime Caching could be used, but would require a user specific key.

据我所知,其他限制和东西你需要知道的与asp.net会议上, ASPNET会话问题

I understand the other limitations and things you need to be aware of with asp.net session, aspnet-session question.

要问这个问题稍微不同的方式:是他们的任何问题或问题,存储一个.NET对象,这只是围绕一个COM对象的包装?

To ask the question a slightly different way: are their any issues or problems with storing an .net object that is just a wrapper around a com object?

推荐答案

我想你会很快得到问题一个请求阻塞另一个。

I think you will very rapidly get problems with one request blocking another.

ASP.NET默认初始化COM其线程放线在多线程单元。 VB6成分为单元模型的最好的。这意味着,当MTA线程创建组件,它的投入主STA如果已经存在(其为ASP.NET工作进程,它不会)或专门为STA创建新线程。不要紧,这MTA线程创建的组件,同样的STA总是用于不能处理MTA模型的组件。这意味着同一个线程用于每个调用的组件,所以并发呼叫在排队等候。

ASP.NET by default initialises COM on its threads to put the thread in a multi-threaded apartment. VB6 components were apartment-model at best. That means that when the MTA thread creates the component, it's put into the main STA if one already exists (which for ASP.NET worker processes, it won't) or a new thread is created specifically for the STA. It doesn't matter which MTA thread creates the component, the same STA is always used for the components that can't handle the MTA model. That means the same thread is used for every call to those components, so concurrent calls have to wait in line.

要告诉ASP.NET初始化COM为单线程的组件,这将至少导致要在同一个线程中执行页面上创建对象,添加 AspCompat 属性的 @Page 指令。

To tell ASP.NET to initialize COM for single-threaded components, which will at least cause the object to be created on the same thread as the executing page, add the AspCompat attribute to the @Page directive.

因为他们很可能有跨线程的问题时,他们再利用,我不会缓存的对象。

I would not cache the objects as they're very likely to have cross-thread issues when they're reused.

这篇关于ASP.NET会话和存储使用对象的COM互操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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