How does delegate.Invoke work?(delegate.Invoke 是如何工作的?)
问题描述
如果我在我的代码中创建一个委托,例如:
If I create a delegate in my code like :
delegate void dostuff (string o);
这会生成一个派生自 System.MulticastDelegate 的类,该类实现了三个方法 - Invoke、BeginInvoke 和 EndInvoke.
This generates a class that derives from System.MulticastDelegate which implements three methods - Invoke, BeginInvoke and EndInvoke.
如果我查看为 Invoke 编译的 IL,我看到的是:
If I look at the compiled IL for Invoke all I see is :
.method public hidebysig newslot virtual
instance void Invoke(string o) runtime managed
{
} // end of method dostuff::Invoke
该方法不包含代码.调用它确实有效 - 委托被调用,但我看不到它是如何做到的.
The method contains no code. Calling it does work - the delegate gets invoked, but I can't see how it does it.
使调用 Invoke 实际调用委托的巫毒从何而来?
Where does the voodoo that makes calling Invoke actually call the delegate come from?
推荐答案
voodoo 可以在签名的末尾找到:runtime managed.请注意,您定义的所有托管类和方法都将被修饰为 cli managed.
The voodoo can be found at the end of the signature: runtime managed. Notice that all of your managed classes and methods that you define will be decorated as cli managed.
runtime managed 表示运行时提供方法的预优化实现.
runtime managed means that the runtime provides pre-optimized implementations of the methods.
这篇关于delegate.Invoke 是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:delegate.Invoke 是如何工作的?
基础教程推荐
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
