.NET Framework Class Library
AppDomain.DoCallBack Method

Executes the code in another application domain that is identified by the specified delegate.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

Syntax

Visual Basic (Declaration)
Public Sub DoCallBack ( _
    callBackDelegate As CrossAppDomainDelegate _
)
Visual Basic (Usage)
Dim instance As AppDomain
Dim callBackDelegate As CrossAppDomainDelegate

instance.DoCallBack(callBackDelegate)
C#
public void DoCallBack (
    CrossAppDomainDelegate callBackDelegate
)
C++
public:
virtual void DoCallBack (
    CrossAppDomainDelegate^ callBackDelegate
) sealed
J#
public final void DoCallBack (
    CrossAppDomainDelegate callBackDelegate
)
JScript
public final function DoCallBack (
    callBackDelegate : CrossAppDomainDelegate
)

Parameters

callBackDelegate

A delegate that specifies a method to call.

Remarks

callBackDelegate can specify a marshal-by-value, MarshalByRefObject, or ContextBoundObject.

Example

The following sample demonstrates using a static DoCallBack method.

Visual Basic
Public Module PingPong

   Private greetings As String = "PONG!"
   
   Sub Main()
      Dim currentDomain As AppDomain = AppDomain.CurrentDomain
      Dim otherDomain As AppDomain = AppDomain.CreateDomain("otherDomain")
      
      greetings = "PING!"

      MyCallBack()
      otherDomain.DoCallBack(AddressOf MyCallBack)

      ' Output:
      '   PING! from default domain
      '   PONG! from otherDomain
   End Sub 'Main
   
   Sub MyCallBack()
      Dim name As String = AppDomain.CurrentDomain.FriendlyName
      Console.WriteLine(greetings + " from " + name)
   End Sub 'MyCallBack

End Module 'PingPong
C#
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);
}
C++
public ref class PingPong
{
private:
   static String^ greetings = "PONG!";

public:
   static void MyCallBack()
   {
      String^ name = AppDomain::CurrentDomain->FriendlyName;
      Console::WriteLine(  "{0} from {1}", greetings, name );
   }

   static void Ping()
   {
      AppDomain^ currentDomain = AppDomain::CurrentDomain;
      AppDomain^ otherDomain = AppDomain::CreateDomain( "otherDomain" );
      greetings = "PING!";
      MyCallBack();
      otherDomain->DoCallBack( gcnew CrossAppDomainDelegate( MyCallBack ) );
      
      // Output:
      //   PING! from default domain
      //   PONG! from otherDomain
   }

};

int main()
{
   PingPong::Ping();
}
J#
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

The following sample demonstrates using the DoCallBack method by value.

Visual Basic
<Serializable> _
Public Class PingPong

   Private greetings As String = "PING!"
   
   Public Shared Sub Main()
      Dim currentDomain As AppDomain = AppDomain.CurrentDomain
      Dim otherDomain As AppDomain = AppDomain.CreateDomain("otherDomain")
      
      Dim pp As New PingPong()
      pp.MyCallBack()
      pp.greetings = "PONG!"
      otherDomain.DoCallBack(AddressOf pp.MyCallBack)

      ' Output:
      '   PING! from default domain
      '   PONG! from otherDomain
   End Sub 'Main
   
   Public Sub MyCallBack()
      Dim name As String = AppDomain.CurrentDomain.FriendlyName
      Console.WriteLine(greetings + " from " + name)
   End Sub 'MyCallBack

End Class 'PingPong
C#
[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);
   }
}
C++
[Serializable]
public ref class PingPong
{
private:
   String^ greetings;

public:
   PingPong()
   {
      greetings = "PING!";
   }

   void MyCallBack()
   {
      String^ name = AppDomain::CurrentDomain->FriendlyName;
      Console::WriteLine(  "{0} from {1}", greetings, name );
   }

   static void Ping()
   {
      AppDomain^ currentDomain = AppDomain::CurrentDomain;
      AppDomain^ otherDomain = AppDomain::CreateDomain( "otherDomain" );
      PingPong^ pp = gcnew PingPong;
      pp->MyCallBack();
      pp->greetings = "PONG!";
      otherDomain->DoCallBack( gcnew CrossAppDomainDelegate( pp, &PingPong::MyCallBack ) );
      
      // Output:
      //   PING! from default domain
      //   PONG! from otherDomain
   }

};

int main()
{
   PingPong::Ping();
}
J#
/** @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

The following sample demonstrates using the DoCallBack method by reference.

Visual Basic
Public Class PingPong
   Inherits MarshalByRefObject

   Private greetings As String = "PING!"
   
   Public Shared Sub Main()
      Dim currentDomain As AppDomain = AppDomain.CurrentDomain
      Dim otherDomain As AppDomain = AppDomain.CreateDomain("otherDomain")
      
      Dim pp As New PingPong()
      otherDomain.DoCallBack(AddressOf pp.MyCallBack)
      pp.MyCallBack()

      ' Output:
      '   PING! from default domain
      '   PONG! from default domain
   End Sub 'Main
   
   Public Sub MyCallBack()
      Dim name As String = AppDomain.CurrentDomain.FriendlyName
      Console.WriteLine((greetings + " from " + name))
      greetings = "PONG!"
   End Sub 'MyCallBack

End Class 'PingPong
C#
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!";
   }
}
C++
public ref class PingPong: public MarshalByRefObject
{
private:
   String^ greetings;

public:
   PingPong()
   {
      greetings = "PING!";
   }

   void MyCallBack()
   {
      String^ name = AppDomain::CurrentDomain->FriendlyName;
      Console::WriteLine( "{0} from {1}", greetings, name );
      greetings = "PONG!";
   }

   static void Ping()
   {
      AppDomain^ currentDomain = AppDomain::CurrentDomain;
      AppDomain^ otherDomain = AppDomain::CreateDomain( "otherDomain" );
      PingPong^ pp = gcnew PingPong;
      otherDomain->DoCallBack( gcnew CrossAppDomainDelegate( pp, &PingPong::MyCallBack ) );
      pp->MyCallBack();
      
      // Output:
      //   PING! from default domain
      //   PONG! from default domain
   }

};

int main()
{
   PingPong::Ping();
}
J#
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
Platforms

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

Version Information

.NET Framework

Supported in: 2.0, 1.1, 1.0
See Also

Tags :


Page view tracker