I have a non-singleton WCF (standalone) service running some COM objects. In non-WCF environments, using Thread.Start, these COM objects happily run in parallel in different threads, utilising all CPUs and completing around the same time.
However, when I try using them in a specific WCF service, things get strange.
When in the registry ApartmentState is set to Both, WCF works, but the tasks seem to be serial, waiting for each other's completion. The CPU usage never exceeds a share of 1 CPU. It's as it is forced to run in STA.
When in the registry ApartmentState is set to Free, it crashes.
I simply don't get it. Is this some kind of piece of plumbing getting in the way?
My WCF service class has the following attributes:
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any, InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]
The COM objects are static / global.
Looks like I might have an answer. Posting in case someone else comes across a similar mystery. The older version was STA only, and the Interop was set to be embedded. Additionally, a prototype of a method was changed. Seemingly, parts taken from the embedded Interop clashed with the COM itself.
Once I changed the setting to No and recompiled everything, it become normal.