Aracılığıyla paylaş


AppDomain.DoCallBack(CrossAppDomainDelegate) Yöntem

Tanım

Kodu, belirtilen temsilci tarafından tanımlanan başka bir uygulama etki alanında yürütür.

public:
 virtual void DoCallBack(CrossAppDomainDelegate ^ callBackDelegate);
public:
 void DoCallBack(CrossAppDomainDelegate ^ callBackDelegate);
public void DoCallBack (CrossAppDomainDelegate callBackDelegate);
abstract member DoCallBack : CrossAppDomainDelegate -> unit
override this.DoCallBack : CrossAppDomainDelegate -> unit
member this.DoCallBack : CrossAppDomainDelegate -> unit
Public Sub DoCallBack (callBackDelegate As CrossAppDomainDelegate)

Parametreler

callBackDelegate
CrossAppDomainDelegate

Çağrılacak yöntemi belirten bir temsilci.

Uygulamalar

Özel durumlar

callBackDelegate, null değeridir.

Örnekler

Aşağıdaki örnekte statik DoCallBack bir yöntemin kullanılması gösterilmektedir.

public ref class PingPong
{
private:
    static String^ greetings = "PONG!";

public:
    static void Main()
    {
        AppDomain^ otherDomain = AppDomain::CreateDomain("otherDomain");

        greetings = "PING!";
        MyCallBack();
        otherDomain->DoCallBack(gcnew CrossAppDomainDelegate(MyCallBack));

        // Output:
        //   PING! from defaultDomain
        //   PONG! from otherDomain
    }

    static void MyCallBack()
    {
        String^ name = AppDomain::CurrentDomain->FriendlyName;

        if (name == AppDomain::CurrentDomain->SetupInformation->ApplicationName)
        {
            name = "defaultDomain";
        }
        Console::WriteLine(greetings + " from " + name);
    }
};

int main()
{
   PingPong::Main();
}
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);
}
open System

let mutable greetings = "PONG!"

let myCallBack () =
    let mutable name = AppDomain.CurrentDomain.FriendlyName

    if name = AppDomain.CurrentDomain.SetupInformation.ApplicationName then
        name <- "defaultDomain"
    printfn $"{greetings} from {name}"

let otherDomain = AppDomain.CreateDomain "otherDomain"
greetings <- "PING!"
myCallBack ()
otherDomain.DoCallBack(CrossAppDomainDelegate myCallBack)

// Output:
//   PING! from defaultDomain
//   PONG! from otherDomain
Public Module PingPong

    Private greetings As String = "PONG!"

    Sub Main()
        Dim otherDomain As AppDomain = AppDomain.CreateDomain("otherDomain")

        greetings = "PING!"
        MyCallBack()
        otherDomain.DoCallBack(AddressOf MyCallBack)

        ' Output:
        '   PING! from defaultDomain
        '   PONG! from otherDomain
     End Sub

     Sub MyCallBack()
        Dim name As String = AppDomain.CurrentDomain.FriendlyName
        If name = AppDomain.CurrentDomain.SetupInformation.ApplicationName Then
            name = "defaultDomain"
        End If
        Console.WriteLine(greetings + " from " + name)
     End Sub

End Module 'PingPong

Aşağıdaki örnekte yöntemin değere göre DoCallBack kullanılması gösterilmektedir.


[Serializable]
public ref class PingPong
{
private:
    String^ greetings;

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

    static void Main()
    {
        AppDomain^ otherDomain = AppDomain::CreateDomain("otherDomain");

        PingPong^ pp = gcnew PingPong();
        pp->MyCallBack();
        pp->greetings = "PONG!";
        otherDomain->DoCallBack(gcnew CrossAppDomainDelegate( pp, &PingPong::MyCallBack));

        // Output:
        //   PING! from defaultDomain
        //   PONG! from otherDomain
    }

    void MyCallBack()
    {
        String^ name = AppDomain::CurrentDomain->FriendlyName;

        if (name == AppDomain::CurrentDomain->SetupInformation->ApplicationName)
        {
            name = "defaultDomain";
        }
        Console::WriteLine(greetings + " from " + name);
    }
};

int main()
{
   PingPong::Main();
}
[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);
    }
}
open System

[<Serializable>]
type PingPong() as this =
    [<DefaultValue>]
    val mutable greetings: string
    do  
        this.greetings <- "PING!"

    member _.MyCallBack() =
        let mutable name = AppDomain.CurrentDomain.FriendlyName

        if name = AppDomain.CurrentDomain.SetupInformation.ApplicationName then
            name <- "defaultDomain"
        printfn $"{this.greetings} from {name}"

let otherDomain = AppDomain.CreateDomain "otherDomain"

let pp = PingPong()
pp.MyCallBack()
pp.greetings <- "PONG!"
otherDomain.DoCallBack(CrossAppDomainDelegate pp.MyCallBack)

// Output:
//   PING! from defaultDomain
//   PONG! from otherDomain
<Serializable> _
Public Class PingPong
     Private greetings As String = "PING!"

     Public Shared Sub Main()
        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 defaultDomain
        '   PONG! from otherDomain
    End Sub

    Public Sub MyCallBack()
        Dim name As String = AppDomain.CurrentDomain.FriendlyName
        If name = AppDomain.CurrentDomain.SetupInformation.ApplicationName Then
            name = "defaultDomain"
        End If
        Console.WriteLine(greetings + " from " + name)
    End Sub

End Class

Aşağıdaki örnekte yöntemin başvuruya göre DoCallBack kullanılması gösterilmektedir.

public ref class PingPong : public MarshalByRefObject
{
private:
   String^ greetings;

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

    static void Main()
    {
        AppDomain^ otherDomain = AppDomain::CreateDomain("otherDomain");

        PingPong^ pp = gcnew PingPong();
        pp->MyCallBack();
        pp->greetings = "PONG!";
        otherDomain->DoCallBack(gcnew CrossAppDomainDelegate( pp, &PingPong::MyCallBack));

        // Output:
        //   PING! from defaultDomain
        //   PONG! from defaultDomain
    }

    // Callback will always execute within defaultDomain due to inheritance from
    // MarshalByRefObject
    void MyCallBack()
    {
        String^ name = AppDomain::CurrentDomain->FriendlyName;
        if (name == AppDomain::CurrentDomain->SetupInformation->ApplicationName)
        {
            name = "defaultDomain";
        }
        Console::WriteLine(greetings + " from " + name);
    }
};

int main()
{
   PingPong::Main();
}
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);
    }
}
open System
type PingPong() as this =
    inherit MarshalByRefObject()
    [<DefaultValue>]
    val mutable greetings: string
    do  
        this.greetings <- "PING!"

    // Callback will always execute within defaultDomain due to inheritance from MarshalByRefObject
    member this.MyCallBack() =
        let mutable name = AppDomain.CurrentDomain.FriendlyName
        if name = AppDomain.CurrentDomain.SetupInformation.ApplicationName then
            name <- "defaultDomain"
        printfn $"{this.greetings} from {name}"

let otherDomain = AppDomain.CreateDomain "otherDomain"

let pp = new PingPong()
pp.MyCallBack()
pp.greetings <- "PONG!"
otherDomain.DoCallBack(CrossAppDomainDelegate pp.MyCallBack)

// Output:
//   PING! from defaultDomain
//   PONG! from defaultDomain
Public Class PingPong
    Inherits MarshalByRefObject

    Private greetings As String = "PING!"
   
    Public Shared Sub Main()
        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 default domain
     End Sub

    ' Callback will always execute within defaultDomain due to inheritance from
    ' MarshalByRefObject
    Public Sub MyCallBack()
        Dim name As String = AppDomain.CurrentDomain.FriendlyName
        If name = AppDomain.CurrentDomain.SetupInformation.ApplicationName Then
            name = "defaultDomain"
        End If
        Console.WriteLine((greetings + " from " + name))
    End Sub

End Class

Açıklamalar

callBackDelegate, veya ContextBoundObjectdeğerlerine göre MarshalByRefObjectsıralama belirtebilir.

Şunlara uygulanır