Bagikan melalui


WorkflowInvoker.EndInvoke(IAsyncResult) Metode

Definisi

Mengembalikan hasil alur kerja yang dipanggil menggunakan salah BeginInvoke satu kelebihan beban.

public:
 System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ EndInvoke(IAsyncResult ^ result);
public System.Collections.Generic.IDictionary<string,object> EndInvoke (IAsyncResult result);
member this.EndInvoke : IAsyncResult -> System.Collections.Generic.IDictionary<string, obj>
Public Function EndInvoke (result As IAsyncResult) As IDictionary(Of String, Object)

Parameter

result
IAsyncResult

IAsyncResult yang mereferensikan BeginInvoke operasi yang memulai alur kerja.

Mengembalikan

Kamus aktivitas OutArgument akar dan InOutArgument nilai yang dikuntah oleh nama argumen yang mewakili output alur kerja.

Contoh

Contoh berikut memanggil alur kerja yang terdiri dari LongRunningDiceRoll aktivitas. Aktivitas LongRunningDiceRoll memiliki dua argumen output yang mewakili hasil operasi pelemparan dadu. Ini diambil dengan memanggil EndInvoke. Ketika panggilan ke EndInvoke kembali, setiap argumen output dikembalikan dalam kamus output, dikuntangani oleh nama argumen.

public sealed class LongRunningDiceRoll : Activity
{
    public OutArgument<int> D1 { get; set; }
    public OutArgument<int> D2 { get; set; }

    public LongRunningDiceRoll()
    {
        this.Implementation = () => new Sequence
        {
            Activities =
            {
                new WriteLine
                {
                    Text = "Rolling the dice for 5 seconds."
                },
                new Delay
                {
                    Duration = TimeSpan.FromSeconds(5)
                },
                new DiceRoll
                {
                    D1 = new OutArgument<int>(env => this.D1.Get(env)),
                    D2 = new OutArgument<int>(env => this.D2.Get(env))
                }
            }
        };
    }
}
static void BeginInvokeExample()
{
    WorkflowInvoker invoker = new WorkflowInvoker(new LongRunningDiceRoll());

    string userState = "BeginInvoke example";
    IAsyncResult result = invoker.BeginInvoke(new AsyncCallback(WorkflowCompletedCallback), userState);

    // You can inspect result from the host to determine if the workflow
    // is complete.
    Console.WriteLine("result.IsCompleted: {0}", result.IsCompleted);

    // The results of the workflow are retrieved by calling EndInvoke, which
    // can be called from the callback or from the host. If called from the
    // host, it blocks until the workflow completes. If a callback is not
    // required, pass null for the callback parameter.
    Console.WriteLine("Waiting for the workflow to complete.");
    IDictionary<string, object> outputs = invoker.EndInvoke(result);

    Console.WriteLine("The two dice are {0} and {1}.",
        outputs["D1"], outputs["D2"]);
}

static void WorkflowCompletedCallback(IAsyncResult result)
{
    Console.WriteLine("Workflow complete.");
}

Keterangan

Untuk diberi tahu ketika alur kerja selesai dan mengambil parameter output alur kerja, panggil EndInvoke dari callback metode yang ditentukan oleh BeginInvoke. Jika EndInvoke dipanggil sebelum alur kerja selesai, alur kerja akan diblokir hingga alur kerja selesai.

Metode ini mengembalikan hasil alur kerja yang dipanggil secara asinkron menggunakan IAsyncResult pola desain asinkron. Untuk informasi selengkapnya, lihat Gambaran Umum Pemrograman Asinkron.

Berlaku untuk