Groups | Blog | Home
all groups > dotnet component services > april 2005 >

dotnet component services : Is it possible to have Component services create a new host each time an object is created



Nick Palmer
4/28/2005 3:48:24 PM
Hi all,

I have a COM object (a dll) and unfortunately for me, this object is single
threaded and I have no way to change this behavior. What I currently do is
host this COM object (the dll) in a ActiveX EXE COM object. So everytime I
need a new instance of the dll COM object, I create a instance of the
ActiveX EXE COM object and this creates an instance of the COM dll object
and returns it. So this way I have a single host for each dll COM object
and I don't have to deal with single threading in the COM dll.

Now, I would like to get away from this way of doing things, and I was
wondering if Component services would provide similar functionality. I've
done some testing with Component services and so far like what I have seen.
I created a Server componnent, and then added my COM dll. Now, when I
create an instance of my COM dll I can see a dllhost.exe app gets created
that is the host for my COM dll. But now, if I launch a second copy of my
testing program , and I create another instance of my COM dll, I do not get
an additional dllhost.exe program. So I'm assuming that both instances of
my COM dll are being hosted by the same dllhost.exe. This is the behavior
that I was trying to avoid. So, is it possible to have Component Services
create a new host app (dllhost.exe) each time I create a new instance of my
COM dll ?

Thanks in advance,
Nick

Olivier Matrot
4/29/2005 12:00:00 AM
Is your goal is to serialize access to your COM object because it is
Apartment threaded, hosting a service component that calls your COM object
in COM+ is one solution. I've had the same problem.

[quoted text, click to view]

Nick Palmer
4/29/2005 8:09:20 AM
Well the problem I'm trying to solve is this. My COM object, the dll COM
object is actually based on a system that we are provided with. The runtime
system for this, while it supports multithreading within its own environment
that we use, is actually not a true multithreaded windows application. So
if you create multiple instances of an object and they are both running at
the same time and hosted by the same process, one will get blocked until
the other one finishes running. This also means that the process gets bound
to a particular CPU on a multi-cpu system thus negating the benefit of
multiple CPU's. So to get around this, I created a cover ActiveX COM EXE
that simply creates an instance of my COM dll and returns it. That means
that each instance of my COM dll is hosted in its own ActiveX COM EXE and
gets its own runtime environment and doesn't have to wait for anybody and is
free to run on any CPU available.

So, I'm trying to duplicate this behavior with Component Services.
Basically I would like to have Component Services create a new dllhost.exe
each time I create an instance of my COM dll object.

I actually think I have discovered how to do this. In the properties for my
server object in Component Services, on the Pooling & Recycling tab, if I
set the Pool Size to its maximum of 999,999 - got the value from the MS
website and others, each time and object creation request comes in,
Component Services will create a new dllhost.exe to host that object until
this number is reached. Since I don't ever anticipate have 999,999 objects
going at any one time I think this might just be what I'm looking for.

Is this what you found out also ?

Nick

[quoted text, click to view]

Olivier Matrot
5/3/2005 12:00:00 AM
On my side, the serviced component is printing on a PDF printer. Since
printing is not multithreaded, the goal for me was (among other things) to
serialize access to the printer, because the serviced component is called
from a web site. COM+ is perfect for this.

[quoted text, click to view]

J. Passing
5/5/2005 12:00:00 AM
Hi,

setting the pool size to a huge value is possible, but not a very nice
solution. Plus, you should be aware of that this solution does not work
on Windows 2000.

The question is why you really want to let COM+ handle this problem. If
your DLL does not need pooling, transaction support, method-level
security or synchronization, COM+ is just unneccessary overhead. And
even if COM+ did support a REGCLS_SINGLEUSE option, the solution would
be the same as you already created yourself - a new dllhost surrorage is
loaded for each activation which in turn loads and activates your DLL.

You could, however, reduce the overhead by putting only a class factory
in your Exe-Server which delegates to the class factory of your dll server.

/Jp

[quoted text, click to view]
AddThis Social Bookmark Button