execute code from different threads
Closed this issue · 6 comments
SimonCropp commented
Any ideas on this one?
var engine = new MsieJsEngine(JsEngineMode.Auto);
//this works
engine.Execute("var foo = 'ddd';");
//this doesnt
var thread = new Thread(() => engine.Execute("var foobar = 'ddd';"));
thread .Start();
Thread.Sleep(10000);
Taritsyn commented
Hello, Simon!
You can't do this! Everything should be run in the one thread.
I recommend you to read the article «JsRT: Runtimes».
SimonCropp commented
thanks. would u take a PR that throws a more useful exception when people attempt this?
Taritsyn commented
What a error message you get?
SimonCropp commented
System.Runtime.InteropServices.COMException was unhandled
HResult=-2147418113
Message=Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
Source=MsieJavaScriptEngine
ErrorCode=-2147418113
StackTrace:
at MsieJavaScriptEngine.ActiveScript.IActiveScriptParse64.ParseScriptText(String code, String itemName, Object context, String delimiter, IntPtr pSourceContextCookie, UInt32 startingLineNumber, ScriptTextFlags flags, Object& result, EXCEPINFO& exceptionInfo)
at MsieJavaScriptEngine.ActiveScript.ActiveScriptParseWrapper.ParseScriptText(String code, String itemName, Object context, String delimiter, IntPtr sourceContextCookie, UInt32 startingLineNumber, ScriptTextFlags flags)
at MsieJavaScriptEngine.ActiveScript.ActiveScriptSiteWrapper.ExecuteScriptText(String code, Boolean isExpression)
at MsieJavaScriptEngine.ActiveScript.ActiveScriptJsEngineBase.Execute(String code)
at MsieJavaScriptEngine.MsieJsEngine.Execute(String code)
SimonCropp commented
It would be better to have an exception
You cannot execute this method on a different thread from which it was constructed.
Taritsyn commented
Hello, Simon!
In MSIE JavaScript Engine version 1.4.0 fixed this error. Now in the ChakraActiveScript
and Classic
modes method calls is performed on single thread.