Main Content

EndInvoke

.NET の System.Delegate 型メソッド BeginInvoke によって開始される非同期呼び出しの結果を取得

    説明

    result = EndInvoke(asyncResult) は、BeginInvoke メソッドによって Microsoft® .NET Framework アプリケーションに対して開始された非同期呼び出しの結果を取得します。同期メソッドの非同期的呼び出しの詳細については、Microsoft .NET のドキュメンテーションを参照してください。

    メモ

    .NET 5 および .NET Core 以降のバージョンを含め、.NET Framework 4.0 以上を使用しているアプリケーションでは、System.Threading.Tasks などのタスク ベースの API を使用します。詳細については、Microsoft の記事 .NET でのタスク ベースの非同期パターン (TAP) を参照してください。

    [res0,...,resN] = EndInvoke(res0,...,resN,asyncResult) (out および/または ref パラメーターをもつメソッド)。

    すべて折りたたむ

    del2int デリゲートは、2 つの入力引数の結果を返します。このデリゲートには out パラメーターも ref パラメーターもありません。

    次の C# デリゲート コードを SignatureExamples という名前のアセンブリの中に構築し、それを MATLAB® に読み込みます。詳細については、MATLAB 例での .NET アプリケーションのビルドを参照してください。

    public delegate Int32 del2int(Int32 arg1, Int32 arg2);
    

    2 つの整数を加算するための次の MATLAB 関数を作成します。

    % Add input arguments
    function res = addfcn(A, B)
    % A and B are numbers
    res = A + B;
    end
    

    デリゲートを作成し、BeginInvoke シグネチャを表示します。

    myDel = SignatureExamples.del2int(@addfcn);
    methodsview(myDel)
    System.IAsyncResult RetVal	
        BeginInvoke	(
            SignatureExamples.del2int this, 
            int32 scalar arg1, 
            int32 scalar arg2, 
            System.AsyncCallback callback, 
            System.Object object)
    

    EndInvoke シグネチャを確認します。

    int32 scalar RetVal	
        EndInvoke	(
            SignatureExamples.del2int this, 
            System.IAsyncResult result)
    

    addfcn を呼び出します。

    asyncRes = myDel.BeginInvoke(6,8,[],[]);
    while asyncRes.IsCompleted ~= true
        pause(0.05) % Use pause() to let MATLAB process event
    end
    result = myDel.EndInvoke(asyncRes)
    
    result =
              14

    delrefvoid デリゲートは ref パラメーター (refArg) を使用します。MATLAB は、引数 ref を RHS 引数および LHS 引数の両方としてマッピングします。

    次の C# デリゲート コードを SignatureExamples という名前のアセンブリの中に構築し、それを MATLAB に読み込みます。

    public delegate void delrefvoid(ref Double refArg);
    

    入力引数をインクリメントして結果を返すための次の MATLAB 関数を作成します。

    % Increment input argument
    function res = incfcn(A)
    % A = number
    res = A + 1;
    end

    デリゲートを作成し、BeginInvoke シグネチャを表示します。

    myDel = SignatureExamples.delrefvoid(@incfcn);
    methodsview(myDel)
    [System.IAsyncResult RetVal, 
    double scalar refArg]	
        BeginInvoke	(
            SignatureExamples.delrefvoid this, 
            double scalar refArg, 
            System.AsyncCallback callback, 
            System.Object object)
    

    EndInvoke シグネチャを確認します。

    double scalar refArg	
        EndInvoke	(
            SignatureExamples.delrefvoid this, 
            double scalar refArg, 
            System.IAsyncResult result)
    

    incfcn を呼び出します。

    x = 6;
    asyncRes = myDel.BeginInvoke(x,[],[]);
    while asyncRes.IsCompleted ~= true
        pause(0.05) % Use pause() to let MATLAB process event
    end
    myRef = 0;
    result = myDel.EndInvoke(myRef,asyncRes);
    disp(['Increment of ' num2str(x) ' = ' num2str(result)]);
    
    Increment of 6 = 7

    deloutsingle デリゲートは out パラメーター (argOut) と 1 つの戻り値を使用します。MATLAB は、引数 out を追加の戻り値としてマッピングします。

    次の C# デリゲート コードを SignatureExamples という名前のアセンブリの中に構築し、それを MATLAB に読み込みます。

    public delegate Single deloutsingle(Single argIn, out Single argOut);
    

    入力引数を 2 倍にするための次の MATLAB 関数を作成します。

    % Double input argument
    function [res1,res2] = times2fcn(A)
    res1 = A*2;
    res2 = res1;
    end

    デリゲートを作成し、BeginInvoke シグネチャを表示します。

    myDel = SignatureExamples.deloutsingle(@times2fcn);
    methodsview(myDel)
    [System.IAsyncResult RetVal, 
    single scalar argOut]	
        BeginInvoke	(
            SignatureExamples.deloutsingle this, 
            single scalar argIn, 
            System.AsyncCallback callback, 
            System.Object object)
    

    EndInvoke シグネチャを確認します。

    [single scalar RetVal, 
    single scalar argOut]	
        EndInvoke	(
            SignatureExamples.deloutsingle this, 
            System.IAsyncResult result)
    

    times2fcn を呼び出します。

    asyncRes = myDel.BeginInvoke(6,[],[]);
    while asyncRes.IsCompleted ~= true
        pause(0.05) % Use pause() to let MATLAB process event
    end
    [a1,a2] = myDel.EndInvoke(asyncRes);
    a1
    
    a1 =
        12

    入力引数

    すべて折りたたむ

    BeginInvoke によって返されるオブジェクト。.NET の System.IAsyncResult オブジェクトとして指定します。

    デリゲートによって返される非同期呼び出しの 0 ~ N 番目 (存在する場合) の結果。任意の有効な型で指定します (out および/または ref パラメーターをもつメソッド)。引数の数は以下の合計です。

    • 戻り値の数 (0 または 1)。

    • out 引数と ref 引数の数。

    出力引数

    すべて折りたたむ

    非同期呼び出しの結果。任意の有効な型で返されます。

    デリゲートによって返される 0 ~ N 番目 (存在する場合) の結果。任意の有効な型で返されます (out および/または ref パラメーターをもつメソッド)。

    バージョン履歴

    R2011a で導入