AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein [gelöst] Liste "by Reference" zwischen AppDomains übergeben
Thema durchsuchen
Ansicht
Themen-Optionen

[gelöst] Liste "by Reference" zwischen AppDomains übergeben

Ein Thema von Waldteufel · begonnen am 17. Mär 2006 · letzter Beitrag vom 18. Mär 2006
Antwort Antwort
Waldteufel
(Gast)

n/a Beiträge
 
#1

[gelöst] Liste "by Reference" zwischen AppDomains

  Alt 17. Mär 2006, 18:04
Hi Community.

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:
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";
    }
  }
}
Dummerweise kommt diese Änderung (config["a"] = "b") aber nie bei dasObjekt an.
Das Programm gibt nur
Code:
config["x"] = "y"
anstatt von
Code:
config["x"] = "y"
config["a"] = "b"
aus.

Weiß jemand, wie man dieses Problem beseitigen könnte?

[edit 2006-03-18 14:18] Formulierung etwas geradegebogen...
  Mit Zitat antworten Zitat
Waldteufel
(Gast)

n/a Beiträge
 
#2

Re: [C#] Liste "by Reference" zwischen AppDomains

  Alt 18. Mär 2006, 16:47
Hi Community.



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.

Code:
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");
    }
  }
}
Wenn man sich vor Augen hält, welcher Code in welcher AppDomain ausgeführt wird, erscheint es im Nachhinein ziemlich simpel.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:01 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz