Retrieve result of asynchronous call initiated by .NET System.Delegate BeginInvoke method
result = EndInvoke(asyncResult)
[res0,...,resN] = EndInvoke(res0,...,resN,asyncResult)
retrieves
result of asynchronous call initiated by result
= EndInvoke(asyncResult
)BeginInvoke
method.
[
for
methods with res0,...,resN
] = EndInvoke(res0,...,resN
,asyncResult
)out
and/or ref
parameters.
|
.NET System.IAsyncResult object returned by
|
|
For methods with
|
|
Results of the asynchronous call. |
|
For methods with |
The following examples show how to call delegates with various input and output arguments. Each example contains:
The C# delegate signature. In order to execute the MATLAB® code,
build the delegate code into an assembly named SignatureExamples
and
load it into MATLAB. For information, see Build a .NET Application for MATLAB Examples.
An example MATLAB function to use with the delegate, which must exist on your path.
The BeginInvoke
and EndInvoke
signatures MATLAB creates.
To display the signatures, create a delegate instance, myDel
,
and call the methodsview
function.
Simple MATLAB example.
This example shows how to use a delegate that has no return value.
C# delegate:
public delegate void delint(Int32 arg);
MATLAB function to call:
% Display input argument function dispfnc(A) % A = number ['Input is ' num2str(A)] end
MATLAB creates the following signatures. For BeginInvoke
:
System.IAsyncResult RetVal BeginInvoke ( SignatureExamples.delint this, int32 scalar arg, System.AsyncCallback callback, System.Object object)
The EndInvoke
signature:
EndInvoke ( SignatureExamples.delint this, System.IAsyncResult result)
Call 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
This example shows how to use a delegate with a return value.
The delegate does not have out
or ref
parameters.
C# delegate:
public delegate Int32 del2int(Int32 arg1, Int32 arg2);
MATLAB function to call:
% Add input arguments function res = addfnc(A, B) % A and B are numbers res = A + B; end
MATLAB creates the following signatures. For BeginInvoke
:
System.IAsyncResult RetVal BeginInvoke ( SignatureExamples.del2int this, int32 scalar arg1, int32 scalar arg2, System.AsyncCallback callback, System.Object object)
The EndInvoke
signature:
int32 scalar RetVal EndInvoke ( SignatureExamples.del2int this, System.IAsyncResult result)
Call 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
This example shows how to use a delegate with a ref
parameter, refArg
,
and no return value.
C# delegate:
public delegate void delrefvoid(ref Double refArg);
MATLAB maps the ref
argument
as both RHS and LHS arguments. MATLAB function to call.
% Increment input argument function res = incfnc(A) % A = number res = A + 1; end
MATLAB creates the following signatures. For BeginInvoke
:
[System.IAsyncResult RetVal, double scalar refArg] BeginInvoke ( SignatureExamples.delrefvoid this, double scalar refArg, System.AsyncCallback callback, System.Object object)
The EndInvoke
signature:
double scalar refArg EndInvoke ( SignatureExamples.delrefvoid this, double scalar refArg, System.IAsyncResult result)
Call 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
This example shows how to use a delegate with an out
parameter, argOut
,
and one return value.
C# delegate:
public delegate Single deloutsingle(Single argIn, out Single argOut);
MATLAB maps the out
argument
as a return value for a total of two return values. MATLAB function
to call.
% Double input argument function [res1,res2] = times2fnc(A) res1 = A*2; res2 = res1; end
MATLAB creates the following signatures. For BeginInvoke
.
[System.IAsyncResult RetVal, single scalar argOut] BeginInvoke ( SignatureExamples.deloutsingle this, single scalar argIn, System.AsyncCallback callback, System.Object object)
The EndInvoke
signature is:
[single scalar RetVal, single scalar argOut] EndInvoke ( SignatureExamples.deloutsingle this, System.IAsyncResult result)
Call 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
If the delegate contains out
or ref
parameters,
the signature for the EndInvoke
method follows
the MATLAB mapping rules. For information, see .NET Delegates With out and ref Type Arguments.