Dear Customer,
Based on my understanding, you are accessing the ATL DLL from VB.NET from
the second thread, but the performance will be lower.
If I have any misunderstanding, please feel free to post here.
1. If we are trying to access unmanaged COM DLL, the .NET code will call
the ATL DLL via RCW wrap, so the performance will be lower than access from
unmanaged code directly. It seems that this is not the case here. Just for
your information.
2. If an ATL object can be accessed from multiple thread depends on the ATL
DLL Developer. If this ATL DLL can live in a MTA apartment, if it has
implemented the multithread accessing synchronization mechanism.
3. Eveny COM Object(ATL object) will have an Threading Modal option in the
registry. So that when the COM Context is trying to activate the object, it
will know where and how to create the object. Such as STA,MTA and
Both(which means the COM Object supports both STA and MTA).
? ThreadingModel value not present: Supports single-threading model.
? ThreadingModel=Apartment : Supports STA model.
? ThreadingModel=Both : Supports STA and MTA model.
? ThreadingModel=Free : Supports only MTA.
If the ATL DLL did not set the ThreadingModel (the first option), then the
DLL will be loaded into the first STA.
Client Server Result
------ ------ -----------------------------------------
STA0 None Direct access; server loaded into STA0
STA* None Proxy access; server loaded into
STA0.
MTA None Proxy access; server loaded into STA0; STA0 created
automatically by COM if necessary;
STA0 Apt Direct access; server loaded into STA0
STA* Apt Direct access; server loaded into STA*
MTA Apt Proxy access; server loaded into an
STA created automatically by COM.
STA0 Free Proxy access; server is loaded into MTA
MTA created automatically by COM if necessary.
STA* Free Same as STA0->Free
MTA Free Direct access
STA0 Both Direct access; server loaded into STA0
STA* Both Direct access; server loaded into STA*
MTA Both Direct access; server loaded into the MTA
If the ATL COM server did not provide the ThreadingModel, the following
scenario will occur.
STA* None Proxy access; server loaded into STA0.
Because the Server did not set ThreadingModal, so the COM infrastructure
will load the ATL DLL into the STA0, i.e. the first STA.
Commonly this is the VB primary thread per your description. That is why it
will access quickly if we create it in the VB primary thread.
STA0 None Direct access; server loaded into STA0
But now if we create another thread to create the ATL DLL, then the new
created thread is in STA*. But the ATL DLL will still be created in the
STA0 based on the rule above.
STA* None Proxy access; server loaded into STA0.
Now the access will across the Proxy, so the performance will be slower.
The above is just my guess. I did not enumerate all the possibility.
Here is KB for your reference.
INFO: Descriptions and Workings of OLE Threading Models
http://support.microsoft.com/kb/q150777/
STA* Both Direct access; server loaded into STA*
STA* Apt Direct access; server loaded into STA*
So far I think our goal is to set the threading Modal to Both or Apartment.
So for detailed information about the Threading Modal, I think you need to
contact the ATL developer.
Also based on my test, the default setting for a ATL project in VS.NET 2005
will be Apartment.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\CLSID\{D7CA6E5B-F292-4E40-80A2-966EC1824CDE}\InprocServer
32]
"ThreadingModel"="Apartment"
We can check the ThreadingModel in the registry key above.
NOTE: the GUID({D7CA6E5B-F292-4E40-80A2-966EC1824CDE}) will differ.
Thanks!
Best regards,
Peter Huang
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.