CoInitialize in C# ?



Hi,

I wanted to instantiate a STA COM component twice, once in the main thread and once in a secondary thread. All worked fine for the main thread, but for the secondary thread, I got 'Query Interface failed' errors when trying to access COM methods.
I once had the same problem in a C++ application. The solution there was to call CoInitialize() for each thread. So I tried the same in C#; I added the following code to my worker thread class:

[DllImport("ole32.dll")]
static extern int CoInitialize(IntPtr pvReserved);

And then called 'CoInitialize((System.IntPtr)null)'
in the worker thread function, before instantiating the 2nd COM object. AND IT WORKED!

Questions:
- Is this allowed?
- Is this correct?
- Isn't there a pendant for CoInitialize() in C#
- If all is wrong, what would be the correct approach?

Thanks in advance
Urs

For direct contact: Remove ALL 4 underscore- characters from e-mail address
.