I have a c# static function that calls into a COM component.
When calling this function from a trivial WPF application it returns correctly. The code might look something like this:
var result = MyClass.StaticCall();
Debug.WriteLine("Hurrah!");
When I call that code, the variable will be set and the debug message output as expected.
If I wrap the same call in a thread, however, it never returns. The failing code might look something like this:
var foo = new Thread(new ThreadStart(() =>
{
var result = MyClass.StaticCall();
Debug.WriteLine("Hurrah!");
}));
foo.Start();
while (foo.IsAlive)
{
}
In this case, StaticCall will not return and the thread is blocked indefinitely.
What might be causing this behaviour?
Additional info:
- Setting the appartment state of the thread makes no difference.
- The last message in the visual studio output window is a notification that the COM interop has been loaded.
- All calls into COM are isolated on the one thread.