![]() |
[gelöst] Liste "by Reference" zwischen AppDomains
Hi Community. :hi:
Dieses Problem macht mich schon seit Tagen verrückt. In meinem Programm verwende ich mehrere AppDomains. Nun möchte ich in der einen AppDomain ein Objekt (genauer gesagt: eine Liste) aus einer anderen AppDomain verändern. Beispiel:
Code:
Dummerweise kommt diese Änderung (config["a"] = "b") aber nie bei dasObjekt an.
using System;
using System.Collections.Generic; using System.Reflection; namespace Beispiel { class dasObjekt : MarshalByRefObject { public Dictionary<string, object> config; public dasObjekt() { config = new Dictionary<string, object>(); } public void huhu() { AppDomain myDomain = AppDomain.CreateDomain("myDomain"); myType myObject = (myType) myDomain.CreateInstanceAndUnwrap( Assembly.GetAssembly(typeof(myType)).FullName, typeof(myType).FullName ); myObject.dingsda(this); } public static void Main() { dasObjekt x = new dasObjekt(); x.config["x"] = "y"; x.huhu(); foreach (KeyValuePair<string, object> y in x.config) Console.WriteLine("config[\"{0}\"] = \"{1}\"", y.Key, y.Value); Console.ReadLine(); } } class myType : MarshalByRefObject { public myType() { } public void dingsda(dasObjekt x) { x.config["a"] = "b"; } } } Das Programm gibt nur
Code:
anstatt von
config["x"] = "y"
Code:
aus. :-(
config["x"] = "y"
config["a"] = "b" Weiß jemand, wie man dieses Problem beseitigen könnte? [edit 2006-03-18 14:18] Formulierung etwas geradegebogen... |
Re: [C#] Liste "by Reference" zwischen AppDomains
Hi Community. :hi:
:bounce1: Ich hab das Problem selbst gelöst. Man muss einfach nur eine Methode definieren, die die Setzung des Werts in der Liste übernimmt, und schon klappts. :wall:
Code:
Wenn man sich vor Augen hält, welcher Code in welcher AppDomain ausgeführt wird, erscheint es im Nachhinein ziemlich simpel.
using System;
using System.Collections.Generic; using System.Reflection; using System.Runtime.Remoting; namespace xyxyxyx { class dasObjekt : MarshalByRefObject { public Dictionary<string, object> config; public dasObjekt() { config = new Dictionary<string, object>(); } public void setConf(string key, object val) { config[key] = val; } public void huhu() { AppDomain myDomain = AppDomain.CreateDomain("myDomain"); myType myObject = myDomain.CreateInstanceAndUnwrap( Assembly.GetAssembly(typeof(myType)).FullName, typeof(myType).FullName ) as myType; myObject.dingsda(this); } public void dump() { foreach (KeyValuePair<string, object> y in config) Console.WriteLine("config[{0}] = {1}", y.Key, y.Value); } public static void Main() { dasObjekt x = new dasObjekt(); x.huhu(); x.dump(); Console.ReadLine(); } } class myType : MarshalByRefObject { public myType() { } public void dingsda(dasObjekt x) { x.setConf("x", "y"); } } } |
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:53 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz