このページの翻訳は最新ではありません。ここをクリックして、英語の最新版を参照してください。
.NET の System.Delegate 型メソッド BeginInvoke によって開始される非同期呼び出しの結果を取得
result = EndInvoke(asyncResult)
[res0,...,resN] = EndInvoke(res0,...,resN,asyncResult)
は、result
= EndInvoke(asyncResult
)BeginInvoke
メソッドによって開始された非同期呼び出しの結果を取得します。
[
(res0,...,resN
] = EndInvoke(res0,...,resN
,asyncResult
)out
および/または ref
パラメーターをもつメソッド)。
|
|
|
|
|
非同期呼び出しの結果。 |
|
|
以下の例は、さまざまな入力引数および出力引数を使用してデリゲートを呼び出す方法を示しています。それぞれの例には以下のものが含まれます。
C# のデリゲート シグネチャです。MATLAB® コードを実行するには、デリゲート コードを SignatureExamples
という名前のアセンブリの中に構築し、それを MATLAB に読み込みます。詳細については、MATLAB 例での .NET アプリケーションのビルドを参照してください。
パス内に存在しなければならない、デリゲートとともに使用するサンプル MATLAB 関数です。
MATLAB が作成する BeginInvoke
シグネチャと EndInvoke
シグネチャです。シグネチャを表示するには、デリゲート インスタンス myDel
を作成し、関数 methodsview
を呼び出します。
MATLAB の簡単な例
この例では、戻り値をもたないデリゲートを使用する方法を説明します。
C# デリゲート:
public delegate void delint(Int32 arg);
呼び出す MATLAB 関数:
% Display input argument function dispfnc(A) % A = number ['Input is ' num2str(A)] end
MATLAB は以下のシグネチャを作成します。BeginInvoke
の場合:
System.IAsyncResult RetVal BeginInvoke ( SignatureExamples.delint this, int32 scalar arg, System.AsyncCallback callback, System.Object object)
EndInvoke
シグネチャ:
EndInvoke ( SignatureExamples.delint this, System.IAsyncResult result)
dispfnc
を呼び出します。
myDel = SignatureExamples.delint(@dispfnc); asyncRes = myDel.BeginInvoke(6, [], []); while asyncRes.IsCompleted ~= true pause(0.05) % Use pause() to let MATLAB process event end myDel.EndInvoke(asyncRes)
Input is 6
この例は、戻り値をもつデリゲートを使用する方法を示しています。このデリゲートには out
パラメーターも ref
パラメーターもありません。
C# デリゲート:
public delegate Int32 del2int(Int32 arg1, Int32 arg2);
呼び出す MATLAB 関数:
% Add input arguments function res = addfnc(A, B) % A and B are numbers res = A + B; end
MATLAB は以下のシグネチャを作成します。BeginInvoke
の場合:
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)
addfnc
を呼び出します。
myDel = SignatureExamples.del2int(@addfnc); 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
この例は、ref
パラメーター refArg
をもち、戻り値をもたないデリゲートを使用する方法を示しています。
C# デリゲート:
public delegate void delrefvoid(ref Double refArg);
MATLAB は、引数 ref
を RHS 引数および LHS 引数の両方としてマッピングします。呼び出す MATLAB 関数は次のようになります。
% Increment input argument function res = incfnc(A) % A = number res = A + 1; end
MATLAB は以下のシグネチャを作成します。BeginInvoke
の場合:
[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)
incfnc
を呼び出します。
x = 6; myDel = SignatureExamples.delrefvoid(@incfnc); 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
この例は、out
パラメーター argOut
をもち、戻り値を 1 つもっているデリゲートを使用する方法を示しています。
C# デリゲート:
public delegate Single deloutsingle(Single argIn, out Single argOut);
MATLAB は、引数 out
を 2 つの戻り値の合計の戻り値としてマッピングします。呼び出す MATLAB 関数は次のようになります。
% Double input argument function [res1,res2] = times2fnc(A) res1 = A*2; res2 = res1; end
MATLAB は以下のシグネチャを作成します。BeginInvoke
の場合:
[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)
times2fnc
を呼び出します。
myDel = SignatureExamples.deloutsingle(@times2fnc); 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
デリゲートに out
または ref
パラメーターが含まれている場合、EndInvoke
メソッドのシグネチャは MATLAB のマッピング ルールに従います。詳細については、out および ref 型の引数をもつ .NET デリゲートを参照してください。