Re: Threading model

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Tony Proctor (tony_proctor_at_aimtechnology_NOSPAM_.com)
Date: 08/11/04


Date: Wed, 11 Aug 2004 16:19:51 +0100


'Apartment threaded' is the norm for DLLs/OCXs. It means that the objects
from the DLL are created in apartment associated with the calling thread.
This is not really an issue unless you're in a multi-threaded environment
(e.g. MTS, IIS, or an ActiveX EXE with a threading option set). Under those
conditions, it is very important.

'Single-threaded' on the other hand, should never be used -- unless you have
an exceptionally good reason. It forces all objects from that DLL to be
created in the main STA apartment. If the thread requesting the creation
isn't the main thread (and it's best not to make such assumptions) then it
would require cross-thread marshalling to invoke it, and that's very slow.

[some background: a process can have multiple STA apartments, but only a
single MTA apartment. The first STA apartment created in a process is also
known as the main STA]

        Tony Proctor

"Fie Fie Niles" <fniles@wincitesystems.com> wrote in message
news:OVsHSm6fEHA.712@TK2MSFTNGP09.phx.gbl...
> What is the difference between apartment threaded model and single
threaded
> model ?
> When creating ActiveX DLL or ActiveX controls, how do you know which
> threading model to choose ?
> Thank you.
>
>
>



Relevant Pages

  • Identify the COM+ apartment I am running in.
    ... C++ COM objects and all COM objects in the host are Apartment threaded. ... host all of the COM objects in the DLL (by referencing the DLL when creating ... STA apartment must have a unique thread in it. ...
    (microsoft.public.vc.atl)
  • Re: COM and Threading problem(I think)
    ... The COM dll is written in C++.Net. ... that it containing single thread apartment objects is ok, ... >> no idea how to change the COM component objects so they run in MTA. ...
    (microsoft.public.dotnet.framework.interop)
  • Re: VB DLL Accessed by Multihreaded Application
    ... A single threaded apartment will only have one thread (or one ... DLL to start creating its own threads using the CreateThread API - it breaks ... I would have thought your DLL would be running on multiple threads if the ... STA for your DLL then there will ...
    (microsoft.public.vb.com)
  • Re: Initializing threading model in VB.
    ... We may be using different terms Ralph but a VB DLL is "Apartment Threaded" ... not specify any threading model. ... "This means that a single-threaded DLL created with Visual Basic is safe ...
    (microsoft.public.vb.com)
  • Re: VC 2005 Beta 2: How to set STA ApartmentState
    ... on DllMain ... > Managed Debugging Assistant 'InvalidApartmentStateChange' has ... enter an apartment in a DLL unless you're doing it in a thread that your DLL ...
    (microsoft.public.dotnet.languages.vc)