Questions tagged [apartments]

Concept in the threading model of the Component Object Model (COM), occurs in terms like STA and MTA

Apartments are groups of Component Object Model (COM) objects which can communicate directly. Communication between apartments is done via proxy, with extra care taken for calls to a Single-Threaded Apartment (STA).

Related tags:

References:

44 questions
400
votes
7 answers

Could you explain STA and MTA?

Can you explain STA and MTA in your own words? Also, what are apartment threads and do they pertain only to COM? If so, why?
John
  • 5,283
  • 4
  • 28
  • 26
41
votes
5 answers

Single-Threaded Apartments vs Multi-Threaded Apartments

Possible Duplicate: Could you explain STA and MTA? All ThreadPool threads are in the multithreaded apartment. --As per the MSDN What does that mean? I am really concerned with what the difference between the multi vs single threaded apartment…
Anthony D
  • 10,227
  • 11
  • 43
  • 67
7
votes
1 answer

About apartment threading models

I have a few questions about Apartments: Was this model introduced for COM purposes only? Can you point to good resources about them? From a thread safety standpoint what does it mean that a component supports STA or MTA model? Thanks.
Ikaso
  • 2,258
  • 19
  • 24
7
votes
2 answers

Legacy VB6 COM+ DLL calling into native Win32 DLL -- threading issues with STA?

Come across what looks at first sight like an MT-issue, but I'm trying to understand in detail the STA model used by COM+. Effectively, I have a legacy COM+ component, written in VB6, that calls into a native (i.e., not-COM) Win32 DLL written in…
Chris J
  • 28,355
  • 4
  • 62
  • 105
6
votes
1 answer

CoInitializeEx returning S_OK when called inside a COM object

Some time ago, I had to modify an old COM DLL (Visual C++ 2010, ATL) migrating it from "Apartment" threading model to "Both", i.e. it can now be called from both STA and MTA threads without serializing calls (of course, I had to add internal…
Demetrio78
  • 165
  • 2
  • 10
5
votes
1 answer

Using CoInitializeEx on WinForms threads

I am working an SDK for a DSLR camera which has the following instructions: Notes on Developing Windows Applications When creating applications that run under Windows, a COM initialization is required for each thread in order to access a camera…
Raheel Khan
  • 13,199
  • 12
  • 71
  • 154
5
votes
1 answer

C# Marshalling COM objects between threads

I'm getting very confused about whether C# marshal's COM objects between threads. To this end I have an application which is loading a set of files in a task parallel fashion. I'm using the StaTaskScehduler to load the files using the COM object. …
Goz
  • 58,120
  • 22
  • 114
  • 192
4
votes
4 answers

Will COM marshalling be (ever) neccessary for an object with ThreadingModel Both?

This is triggered by another question. Specifically, I have a in process COM class, that is defined in the CLSID registry as having a ThreadingModel of Both. Our process activates this object through CoCreateInstance (not CoCreateInstanceEx, if that…
Martin Ba
  • 33,741
  • 27
  • 150
  • 304
3
votes
0 answers

Error 'Unable to cast COM object of type' when crossing thread apartments in C#

I've been working with a third party SDK as a referenced dll from within C# using .NET 4.5.2 on Windows 10. The IDE creates an Interop around the dll and I can see the appropriate namespaces, interfaces, enum, etc. The SDK I am working with is for…
Geo...
  • 235
  • 1
  • 11
3
votes
2 answers

Perform screen-scape of Webbrowser control in thread

I am using the technique shown in WebBrowser Control in a new thread Trying to get a screen-scrape of a webpage I have been able to get the following code to successfully work when the WebBrowser control is placed on a WinForm. However it fails…
3
votes
1 answer

ActiveX control cannot be instantiated because thread is in a single-threaded apartment. Happens after waking PC from sleep

I am working on a VOIP client (Window's form) that opens a browser window (ExtendedWebBrowser) when a call is made or received. Normally it works fine but if the computer is put into sleep mode and then woken the program will crash with the…
2
votes
1 answer

Asynchronous operations within an asynchronous operation

My multi-threading knowledge is still pretty rudimentary, so would really appreciate some pointers here. I have an interface, IOperationInvoker (from WCF) which has the following methods: IAsyncResult InvokeBegin(object instance, object[] inputs,…
James Crowley
  • 3,395
  • 4
  • 31
  • 55
2
votes
1 answer

How to get the main thread of a console app to be MTA?

With Delphi, how can I create a (Windows) console application that has a main thread that is initialized as COINIT_MULTITHREADED? If I call CoInitializeEx(nil, COINIT_MULTITHREADED) in the very first statement, I get a HRESULT 0x80010106 (Cannot…
Martin
  • 1,752
  • 13
  • 25
2
votes
1 answer

ATL sample of calling (marshalling) Apartment-threaded COM interfaces from a worker thread

I'm looking for a code sample which illustrates making cross-threaded COM calls in an ATL COM Server DLL. Know one? More details: My component is an IE Browser Helper Object which needs to do work on a background thread. In one of my object's…
Justin Grant
  • 41,265
  • 11
  • 110
  • 185
2
votes
1 answer

How can I set thread in PowerShell with executable scriptblock and ApartmentState argument?

How can I set thread and start it with some executable code with ApartmentState = "STA"? I just find this method but I don't know how I can pass my scriptblock to it. $r = [RunspaceFactory]::CreateRunspace() $r.ApartmentState = 'STA' $r.Open() I…
user7377479
1
2 3