Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
281 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...