EndInvoke
检索 .NET System.Delegate BeginInvoke 方法启动的异步调用结果
说明
检索 Microsoft® .NET Framework 应用程序的 result
= EndInvoke(asyncResult
)BeginInvoke
方法启动的异步调用结果。有关异步调用同步方法的信息,请参考 Microsoft .NET 文档。
注意
对于使用 .NET Framework 4.0 和更高版本(包括 .NET 5 和 .NET Core 及更高版本)的应用程序,请使用基于任务的 API,如 System.Threading.Tasks
。有关详细信息,请参阅 Microsoft 文章 .NET 中基于任务的异步模式 (TAP)。
[
(对于带 res0,...,resN
] = EndInvoke(res0,...,resN
,asyncResult
)out
和/或 ref
参数的方法)。
示例
用返回值调用委托
del2int
委托返回两个输入参量的结果。委托没有 out
或 ref
参数。
将此 C# 委托代码构建到名为 SignatureExamples
的程序集中,并将其加载到 MATLAB® 中。有关信息,请参阅Build a .NET Application for MATLAB Examples。
public delegate Int32 del2int(Int32 arg1, Int32 arg2);
创建此 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
使用 ref
参数调用委托
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
使用 out
参数调用委托
deloutsingle
委托使用 out
参数 (argOut
) 和一个返回值。MATLAB 将 out
参量映射为附加返回值。
将此 C# 委托代码构建到名为 SignatureExamples
的程序集中,并将其加载到 MATLAB 中。
public delegate Single deloutsingle(Single argIn, out Single argOut);
创建此 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
输入参数
asyncResult
— 对象
System.IAsyncResult
由 BeginInvoke
返回的对象,指定为 .NET System.IAsyncResult
对象。
res0,...,resN
— 结果
任何有效类型
委托返回的异步调用的结果 0 到 N(如果有),指定为任一有效类型。对于带 out
和/或 ref
参数的方法。参量数量是以下项的总和:
返回值(
0
或1
)的数目。out
和ref
参量的数目。
输出参量
result
— 结果
任何有效类型
异步调用的结果,以任一有效类型形式返回。
res0,...,resN
— 结果
任何有效类型
委托返回的结果 0 到 N(如果有),以任一有效类型形式返回。对于带 out
和/或 ref
参数的方法。
版本历史记录
在 R2011a 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)