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 是如何工作的?
基础教程推荐
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 如果条件可以为空 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 将数据集转换为列表 2022-01-01
