We were having a discussion at the office on how to solve a particular problem and using an event was raised (no pun intended). The response was negative citing misuse and that they can be expensive.
I understand the concerns behind misuse and I know that they are just a special multicast delegate but given a scenario where there is at most one listener why would using an event over a method call be considered “expensive”?
Update:
Just to be clear this is not about any particular implementation this is a more general question about the cost of using an event over a method call.
Test it in your scenario – I would imagine that many, many factors can affect this, especially when we’re talking something with such a low relative cost as a method/delegate call.
A quick and simple test with a release build not under a debugger, compiled under 4.0 as “any cpu”, and running on 64-bit windows 7:
Another Edit: Oops Here’s a better result. See the code for how it’s working
So in a straight “do nothing test” with ten million calls, an event adds .474 sec [edit, only .026 now on a much better machine, still roughly double however]
I would worry more about correctness of design than half a second every 10 million calls, unless you are expecting to do that many calls in short periods of time (in which case perhaps there is a more fundamental design issue).