次の方法で共有


AppDomain.DoCallBack メソッド

指定したデリゲートで識別される、別のアプリケーション ドメイン内のコードを実行します。

Public Overridable Sub DoCallBack( _
   ByVal callBackDelegate As CrossAppDomainDelegate _) Implements _AppDomain.DoCallBack
[C#]
public virtual void DoCallBack(CrossAppDomainDelegatecallBackDelegate);
[C++]
public: virtual void DoCallBack(CrossAppDomainDelegate* callBackDelegate);
[JScript]
public function DoCallBack(
   callBackDelegate : CrossAppDomainDelegate);

パラメータ

  • callBackDelegate
    呼び出すメソッドを指定するデリゲート。

実装

_AppDomain.DoCallBack

解説

callBackDelegate には、値渡しによるマーシャリング オブジェクト、 MarshalByRefObject 、または ContextBoundObject を指定できます。

使用例

[Visual Basic, C#, C++] 静的な DoCallBack メソッドの使用方法を次のサンプルで示します。

 
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 __gc class PingPong {
   static String* greetings = S"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(S"otherDomain");

      greetings = S"PING!";

      MyCallBack();
      otherDomain->DoCallBack(new CrossAppDomainDelegate(0, MyCallBack));

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

int main() {
   PingPong::Ping();
}

[Visual Basic, C#, C++] 値渡しによる DoCallBack メソッドの使用方法を次のサンプルで示します。

 
<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 __gc class PingPong {
private:
   String* greetings;

public:
   PingPong() {
      greetings = S"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(S"otherDomain");

      PingPong* pp = new PingPong();
      pp->MyCallBack();
      pp->greetings = S"PONG!";
      otherDomain->DoCallBack(new CrossAppDomainDelegate(pp, &PingPong::MyCallBack));

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

int main() {
   PingPong::Ping();
}

[Visual Basic, C#, C++] 参照渡しによる DoCallBack メソッドの使用方法を次のサンプルで示します。

 
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 __gc class PingPong : public MarshalByRefObject {
private:
   String* greetings;

public:
   PingPong() {
      greetings = S"PING!";
   }
   void MyCallBack() {
      String* name = AppDomain::CurrentDomain->FriendlyName;
      Console::WriteLine(S"{0} from {1}", greetings, name);
      greetings = S"PONG!";
   }
   static void Ping() {
      AppDomain*  currentDomain = AppDomain::CurrentDomain;
      AppDomain*  otherDomain = AppDomain::CreateDomain(S"otherDomain");

      PingPong* pp = new PingPong();
      otherDomain->DoCallBack(new CrossAppDomainDelegate(pp, &PingPong::MyCallBack));
      pp->MyCallBack();

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

int main() {
   PingPong::Ping();
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

.NET Framework セキュリティ:

参照

AppDomain クラス | AppDomain メンバ | System 名前空間