public WSHBridge() { queueAvailable = new Semaphore(0, int.MaxValue); workAvailable = new Semaphore(0, int.MaxValue); resultAvailable = new Semaphore(0, int.MaxValue); plugin = new WSHPlugin(this); javaScriptThread = new Thread (() => { var instance = Activator.CreateInstance(typeof(Host.EcmaScript)); scriptEngine = (Host.IActiveScript)instance; parser = (Host.IActiveScriptParse)instance; var site = new WSHScriptSite(plugin); HResult.ThrowOnFailure(scriptEngine.SetScriptSite(site)); HResult.ThrowOnFailure (scriptEngine.AddNamedItem (WSHScriptSite.GlobalPluginName, Host.ScriptItem.IsVisible | Host.ScriptItem.IsSource)); HResult.ThrowOnFailure(parser.InitNew()); queueAvailable.Release(); while (true) { workAvailable.WaitOne(); try { work(); result = null; } catch (Exception e) { result = e; } resultAvailable.Release(); } }); javaScriptThread.Name = "Microsoft.LiveLabs.WSHInteropManager.WorkerThread"; javaScriptThread.IsBackground = true; javaScriptThread.Start(); }