private void SetHostOjectField(ICSharpScriptObjectFieldAccesor scriptObject, string fieldName, object obj) { if (scriptObject == null) { return; } while (true) { try { if (!executeInSeparateAppDomain) { scriptObject.SetField(fieldName, obj); } else { scriptObject.SetField(fieldName, ObjectAddress.GetAddress(obj)); } break; } catch (NotSupportedException) { // capture the exception and try again. This happens because there was a GC call between // the time we obtained the raw address of obj and the call to SetField() } } }
private void SetObjectsInScope(ICSharpScriptObjectFieldAccesor scriptObject) { lock (this) foreach (var obj in objectsInScope) { SetHostOjectField(scriptObject, obj.Key, obj.Value); } }