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

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

问题描述

我在asp.net网站上工作。我们必须使用com interop与旧版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包装,是明智的还是建议在会话中持久化这样的对象?

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?

此外,上下文对象包含用户特定信息,因此使用.net 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-session问题

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线程创建组件时,如果已经存在(对于ASP.NET工作进程,它不会)或者为STA专门创建新线程,则将其放入主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天全站免登陆