event.Invoke(参数)与事件(参数)。这是更快? [英] event.Invoke(args) vs event(args). Which is faster?

查看:195
本文介绍了event.Invoke(参数)与事件(参数)。这是更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是更快;使用event.Invoke(参数),或者只调用事件(参数)。有什么不同?比另一个更快或更慢;或者是preference它只是一个问题?

Which is faster; using event.Invoke(args), or just calling event(args). What's the difference? Is one faster or slower than the other; or is it just a matter of preference?

推荐答案

someDelegate(...)是一个编译器速记 someDelegate。调用(...)
他们都编译为相同的IL— A callvirt 指令的委托类型的调用方法

Writing someDelegate(...) is a compiler shorthand for someDelegate.Invoke(...).
They both compile to the same IL—a callvirt instruction to that delegate type's Invoke method.

调用方法是由编译器为每个具体的委托类型产生的。

The Invoke method is generated by the compiler for each concrete delegate type.

相反, DynamicInvoke 方法的基础上定义的代理键入,使用反射调用委托和是缓慢的。

By contrast, the DynamicInvoke method, defined on the base Delegate type, uses reflection to call the delegate and is slow.

这篇关于event.Invoke(参数)与事件(参数)。这是更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆