Taritsyn/MsieJavaScriptEngine

execute code from different threads

Closed this issue · 6 comments

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);

Hello, Simon!

You can't do this! Everything should be run in the one thread.
I recommend you to read the article «JsRT: Runtimes».

thanks. would u take a PR that throws a more useful exception when people attempt this?

What a error message you get?

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)

It would be better to have an exception

You cannot execute this method on a different thread from which it was constructed.

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.