-
Notifications
You must be signed in to change notification settings - Fork 4
Gendarme.Rules.Performance.ConsiderCustomAccessorsForNonVisibleEventsRule(2.10)
Assembly: Gendarme.Rules.Performance
Version: 2.10
This rule looks for non-visible events to see if their add/remove accessors are the default ones. The default, compiler generated, accessor is marked as synchronized which means that the runtime will bracket them between Monitor.Enter and Monitor.Exit calls. This is the safest approach unless, for non-visible events, you have a performance bottleneck around the events. In this case you should review if your code needs the locks or if you can provide an alternative to them.
Bad example:
private event EventHandler<TestEventArgs> TimeCritical;
Good example:
static object TimeCriticalEvent = new object ();
EventHandlerList events = new EventHandlerList ();
private event EventHandler<TestEventArgs> TimeCritical {
add {
events.AddHandler (TimeCriticalEvent, value);
}
remove {
events.AddHandler (TimeCriticalEvent, value);
}
}
- This rule is available since Gendarme 2.0
Note that this page was autogenerated (3/17/2011 9:31:58 PM) based on the xmldoc
comments inside the rules source code and cannot be edited from this wiki.
Please report any documentation errors, typos or suggestions to the
Gendarme Mailing List. Thanks!