private void RunScriptCore(byte[] inMemoryAssembly, byte[] inMemorySymbolStore, TextWriter outputTextWriter, TextWriter errorTextWriter) { RemoteScriptRun scriptRun; lock (fieldsLock) { if (inMemoryAssembly != loadedAssembly) { if (scriptAppDomain != null) { AppDomain.Unload(scriptAppDomain); } scriptAppDomain = AppDomain.CreateDomain("ScriptAppDomain"); remoteScriptRun = (RemoteScriptRun)scriptAppDomain.CreateInstanceAndUnwrap(typeof(RemoteScriptRun).Assembly.FullName, typeof(RemoteScriptRun).FullName); remoteScriptRun.Load(inMemoryAssembly, inMemorySymbolStore, outputTextWriter, errorTextWriter); loadedAssembly = inMemoryAssembly; } scriptRun = remoteScriptRun; } try { scriptRun?.Run(); } catch (AppDomainUnloadedException) { } }
private void StopScriptCore() { lock (fieldsLock) { if (scriptAppDomain != null) { AppDomain.Unload(scriptAppDomain); scriptAppDomain = null; loadedAssembly = null; remoteScriptRun = null; } } }