0

I have the following sceanrio:

void Method_A()
{
    Method_B();
}

void Method_B()
{
    Method_C();
}

Now I do this:

Thread myThread = new Thread(Method_A);
myThread.Start();

and I get the following exception:

This operation failed because the QueryInterface call on the COM component for the interface with IID '{9149349D-5A91-11CF-8700-00AA0060263B}' failed due to the following error: The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD)).

How to call all sub-called methods on the same thread which different from the main thread?

Ivan
  • 1,081
  • 2
  • 17
  • 43
  • You are dealing with COM objects inside these methods. Without the relevant code, it is impossible to help. – Yacoub Massad May 05 '16 at 13:54
  • This doesn't go wrong like this very often in .NET, the CLR never gets this wrong. So this probably comes from the COM component itself, could happen when it is an out-of-process server and it doesn't marshal the interface pointer correctly when you created the object in an MTA thread. Pretty unreasonable to force us to guess at that btw. Making code that hates threading behave correctly when you use threads requires you to [take care of it yourself](http://stackoverflow.com/a/21684059/17034). – Hans Passant May 05 '16 at 15:22

0 Answers0