The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
AppDomain.DoCallBack Method (CrossAppDomainDelegate)
.NET Framework (current version)
Executes the code in another application domain that is identified by the specified delegate.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- callBackDelegate
-
Type:
System.CrossAppDomainDelegate
A delegate that specifies a method to call.
| Exception | Condition |
|---|---|
| ArgumentNullException | callBackDelegate is null. |
callBackDelegate can specify a marshal-by-value, MarshalByRefObject, or ContextBoundObject.
The following sample demonstrates using a static DoCallBack method.
static string greetings = "PONG!"; public static void Main() { AppDomain otherDomain = AppDomain.CreateDomain("otherDomain"); greetings = "PING!"; MyCallBack(); otherDomain.DoCallBack(new CrossAppDomainDelegate(MyCallBack)); // Output: // PING! from defaultDomain // PONG! from otherDomain } static public void MyCallBack() { string name = AppDomain.CurrentDomain.FriendlyName; if (name == AppDomain.CurrentDomain.SetupInformation.ApplicationName) { name = "defaultDomain"; } Console.WriteLine(greetings + " from " + name); }
The following sample demonstrates using the DoCallBack method by value.
[Serializable] public class PingPong { private string greetings = "PING!"; public static void Main() { AppDomain otherDomain = AppDomain.CreateDomain("otherDomain"); PingPong pp = new PingPong(); pp.MyCallBack(); pp.greetings = "PONG!"; otherDomain.DoCallBack(new CrossAppDomainDelegate(pp.MyCallBack)); // Output: // PING! from defaultDomain // PONG! from otherDomain } public void MyCallBack() { string name = AppDomain.CurrentDomain.FriendlyName; if (name == AppDomain.CurrentDomain.SetupInformation.ApplicationName) { name = "defaultDomain"; } Console.WriteLine(greetings + " from " + name); } }
The following sample demonstrates using the DoCallBack method by reference.
public class PingPong : MarshalByRefObject { private string greetings = "PING!"; public static void Main() { AppDomain otherDomain = AppDomain.CreateDomain("otherDomain"); PingPong pp = new PingPong(); pp.MyCallBack(); pp.greetings = "PONG!"; otherDomain.DoCallBack(new CrossAppDomainDelegate(pp.MyCallBack)); // Output: // PING! from defaultDomain // PONG! from defaultDomain } // Callback will always execute within defaultDomain due to inheritance from // MarshalByRefObject public void MyCallBack() { string name = AppDomain.CurrentDomain.FriendlyName; if (name == AppDomain.CurrentDomain.SetupInformation.ApplicationName) { name = "defaultDomain"; } Console.WriteLine(greetings + " from " + name); } }
.NET Framework
Available since 1.1
Available since 1.1
Show: