When I try to call a extern method from a non-main thread, I get COM CoInitialize error from the DLL written in C++ thread.
Just for slight more details, I have define an alias to call the c++ method in my C# console project.
e.g. [DllImport("WRITTENINC++.dll", CharSet = CharSet.Ansi)] public static extern Int32 DOTHIS(string s1, string s2, ref double d1, ref double d2);
And I put [STAThread] on top of Program.Main method.
When I call the method in the main thread, I get the correct result. However, if I run the same lines of codes in a different thread (using System.Threading and thread.Start()), I get the error regarding COM initialization.
Assuming that I cannot modify the DLL, the only way right now is to restrict my program to single-thread, which is not exciting.
Is there any solution to this?
Thanks!