DoCallBack (Método)

AppDomain.DoCallBack (Método)

Ejecuta el código en otro dominio de aplicación identificado por el delegado especificado.

Espacio de nombres: System
Ensamblado: mscorlib (en mscorlib.dll)

public void DoCallBack (
	CrossAppDomainDelegate callBackDelegate
)
public final void DoCallBack (
	CrossAppDomainDelegate callBackDelegate
)
public final function DoCallBack (
	callBackDelegate : CrossAppDomainDelegate
)

Parámetros

callBackDelegate

Delegado que especifica un método al que se va a llamar.

callBackDelegate puede especificar un cálculo de referencias por valor, MarshalByRefObject o ContextBoundObject.

En el siguiente ejemplo se muestra el uso del método estático DoCallBack.

static string greetings = "PONG!";

public static void Main() {
   AppDomain currentDomain = AppDomain.CurrentDomain;
   AppDomain otherDomain = AppDomain.CreateDomain("otherDomain");

   greetings = "PING!";

   MyCallBack();
   otherDomain.DoCallBack(new CrossAppDomainDelegate(MyCallBack));

   // Output:
   //   PING! from default domain
   //   PONG! from otherDomain
}

static public void MyCallBack() {
   string name = AppDomain.CurrentDomain.FriendlyName;
   Console.WriteLine(greetings + " from " + name);
}

private static String greetings = "PONG!";

public static void main(String[] args)
{
    AppDomain currentDomain = AppDomain.get_CurrentDomain();
    AppDomain otherDomain = AppDomain.CreateDomain("otherDomain");
    greetings = "PING!";
    MyCallBack();
    otherDomain.DoCallBack(new CrossAppDomainDelegate(MyCallBack));
    // Output:
    // PING! from default domain
    // PONG! from otherDomain
} //main
   
public static void MyCallBack()
{
    String name = AppDomain.get_CurrentDomain().get_FriendlyName();
    Console.WriteLine(greetings + " from " + name);
} //MyCallBack

En el siguiente ejemplo se muestra el uso del método DoCallBack por valor.

[Serializable]
public class PingPong {
   private string greetings = "PING!";
   
   public static void Main() {
      AppDomain currentDomain = AppDomain.CurrentDomain;
      AppDomain otherDomain = AppDomain.CreateDomain("otherDomain");

      PingPong pp = new PingPong();
      pp.MyCallBack();
      pp.greetings = "PONG!";
      otherDomain.DoCallBack(new CrossAppDomainDelegate(pp.MyCallBack));

      // Output:
      //   PING! from default domain
      //   PONG! from otherDomain
   }
   
   public void MyCallBack() {
      string name = AppDomain.CurrentDomain.FriendlyName;
      Console.WriteLine(greetings + " from " + name);
   }
}

/** @attribute Serializable()
 */
public class PingPong
{
    private String greetings = "PING!";

    public static void main(String[] args)
    {
        AppDomain currentDomain = AppDomain.get_CurrentDomain();
        AppDomain otherDomain = AppDomain.CreateDomain("otherDomain");
        PingPong pp = new PingPong();
        pp.MyCallBack();
        pp.greetings = "PONG!";
        otherDomain.DoCallBack(new CrossAppDomainDelegate(pp.MyCallBack));
        // Output:
        // PING! from default domain
        // PONG! from otherDomain
    } //main
   
    public void MyCallBack()
    {
        String name = AppDomain.get_CurrentDomain().get_FriendlyName();
        Console.WriteLine(greetings + " from " + name);
    } //MyCallBack
} //PingPong

En el siguiente ejemplo se muestra el uso del método DoCallBack por referencia.

public class PingPong : MarshalByRefObject {
   private string greetings = "PING!";
   
   public static void Main() {
      AppDomain currentDomain = AppDomain.CurrentDomain;
      AppDomain otherDomain = AppDomain.CreateDomain("otherDomain");

      PingPong pp = new PingPong();
      otherDomain.DoCallBack(new CrossAppDomainDelegate(pp.MyCallBack));
      pp.MyCallBack();


      // Output:
      //   PING! from default domain
      //   PONG! from default domain
   }
   
   public void MyCallBack() {
      string name = AppDomain.CurrentDomain.FriendlyName;
      Console.WriteLine(greetings + " from " + name);
      greetings = "PONG!";
   }
}

public class PingPong extends MarshalByRefObject
{
    private String greetings = "PING!";

    public static void main(String[] args)
    {
        AppDomain currentDomain = AppDomain.get_CurrentDomain();
        AppDomain otherDomain = AppDomain.CreateDomain("otherDomain");
        PingPong pp = new PingPong();
        otherDomain.DoCallBack(new CrossAppDomainDelegate(pp.MyCallBack));
        pp.MyCallBack();
        // Output:
        // PING! from default domain
        // PONG! from default domain
    } //main
    
    public void MyCallBack()
    {
        String name = AppDomain.get_CurrentDomain().get_FriendlyName();
        Console.WriteLine(greetings + " from " + name);
        greetings = "PONG!";
    } //MyCallBack
} //PingPong

Windows 98, Windows 2000 SP4, Windows Millennium, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter Edition

.NET Framework no admite todas las versiones de cada plataforma. Para obtener una lista de las versiones admitidas, vea Requisitos del sistema.

.NET Framework

Compatible con: 2.0, 1.1, 1.0

Adiciones de comunidad

AGREGAR
Mostrar:
© 2016 Microsoft