Taritsyn / MsieJavaScriptEngine

.NET wrapper for working with the JavaScript engines of Internet Explorer and Edge Legacy.
Apache License 2.0
106 stars 22 forks source link

execute code from different threads #3

Closed SimonCropp closed 10 years ago

SimonCropp commented 10 years ago

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 10 years ago

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 10 years ago

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

Taritsyn commented 10 years ago

What a error message you get?

SimonCropp commented 10 years ago
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 10 years ago

It would be better to have an exception

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

Taritsyn commented 10 years ago

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.