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 是如何工作的?
- 输入按键事件处理程序 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
