AppDomain.DoCallBack Method
Executes the code in another application domain that is identified by the specified delegate.
[Visual Basic] Public Overridable Sub DoCallBack( _ ByVal callBackDelegate As CrossAppDomainDelegate _ ) Implements _AppDomain.DoCallBack [C#] public virtual void DoCallBack( CrossAppDomainDelegate callBackDelegate ); [C++] public: virtual void DoCallBack( CrossAppDomainDelegate* callBackDelegate ); [JScript] public function DoCallBack( callBackDelegate : CrossAppDomainDelegate );
Parameters
- callBackDelegate
- A delegate that specifies a method to call.
Implements
Remarks
callBackDelegate can specify a marshal-by-value, MarshalByRefObject, or ContextBoundObject.
Example
[Visual Basic, C#, C++] 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 __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++] 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 __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++] 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 __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] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
.NET Framework Security:
- ReflectionPermission when invoked late-bound through mechanisms such as Type.InvokeMember. Associated enumeration: ReflectionPermissionFlag.MemberAccess.