- Home /
Error: Failed to set the specified COM apartment state & Canon EDSDK
Hi~~
I am trying integrate Canon EDSDK with Unity3D (5.6.1) by referencing Canon EDSDK's Visual Studio project from >> https://www.codeproject.com/Articles/688276/Canon-EDSDK-Tutorial-in-Csharp << , created by "Johannes Bildstein".
In his project, it will call thread.SetApartmentState
when creating thread. And I found that my project is not functioning after I convert the visual Studio UI to Unity UI.
There are NO error message when testing on Unity Editor and Unity's log.txt file. But "Failed to set the specified COM apartment state" was show in output_log.txt after I build and run the project in .exe.
After that, I try to delete the line (`thread.SetApartmentState(ApartmentState.STA);`) or change the STA to MTA or Unknown but the project still not functioning after build the ".exe" . However, the project is functioning in Editor after I modify the code. Any idea why this happening?
More Detail:
In Johannes Bildstein's visual studio project has a class call STAThread
for handling mainThread
object. To create mainThread
object, STAThread
has a method CreateThread
to create mainThread
object.
public static Thread CreateThread(Action action){
var thread = new Thread(new ThreadStart(action));
thread.SetApartmentState(ApartmentState.STA);
return thread;
}
public void Start() {
lock (runLock) {
if (!isRunning) {
mainThread = CreateThread(ExecutionLoop);
isRunning = true;
mainThread.Start();
WaitForThread();
}
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Flip over an object (smooth transition) 3 Answers
Dll distribution of Conditionally Compiled project 0 Answers
Having issues using my .dlls 1 Answer