AppDomain.DoCallBack Method

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

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

public:
virtual void DoCallBack (
	CrossAppDomainDelegate^ callBackDelegate
) sealed
public final void DoCallBack (
	CrossAppDomainDelegate callBackDelegate
)
public final function DoCallBack (
	callBackDelegate : CrossAppDomainDelegate
)
Not applicable.

Parameters

callBackDelegate

A delegate that specifies a method to call.

Exception typeCondition

ArgumentNullException

callBackDelegate is a null reference (Nothing in Visual Basic).

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

The following sample demonstrates using a static DoCallBack method.

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();
}


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.


[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();
}


/** @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.

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();
}


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 Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show: