delegate.Invoke 是如何工作的?

How does delegate.Invoke work?(delegate.Invoke 是如何工作的?)
本文介绍了delegate.Invoke 是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在我的代码中创建一个委托,例如:

If I create a delegate in my code like :

delegate void dostuff (string o);

这会生成一个派生自 System.MulticastDelegate 的类,该类实现了三个方法 - InvokeBeginInvokeEndInvoke.

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 是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)