Update : I wrote a program to check the memory implications for each of the methods that I mentioned below. Not surprisingly, I found that, of course, the conventional approach using .NET events creates a lot more garbage than other approaches (which means that it actually creates garbage, unlike the other two strategies that do not seem to create any garbage at all).
In fact, I had to emphasize all the time that I was more interested in the memory overhead of TEventArgsarguments in .NET events than in terms of speed. Ultimately, I must admit that for all practical purposes - in terms of both memory and speed - the cost is negligible. However, it seemed to me that it was interesting to see that when a lot of events happen, the “normal” method is really worth it, and that in extreme cases it can even lead to garbage collection 1, which may or may not matter depending from the situation (the more “in real time” the system should be, in my experience, the more important it is to remember where the garbage is created and how to minimize it, if necessary).
This may seem like a silly question. I understand that Windows Forms, for example, can easily be regarded as a “high-performance” scenario, with hundreds or even thousands of events occur very quickly (for example, an event Control.MouseMove) all the time. But still, I wonder if it is really wise to create a class with .NET events when it is expected that the class will be used in high-performance time-critical code.
, , , - EventHandler<TEventArgs>, TEventArgs EventArgs , , , , /. ( EventsArgs, , , EventArgs.Empty, , - TEventArgs, , ). , GC, .
, , , :
- (..
EventHandler<TEventArgs>) , , int, double .. ( string, ). - , . , , .
, GC- .NET ? , ? , - , , , ?