Gendarme.Rules.Performance.ConsiderCustomAccessorsForNonVisibleEventsRule Class
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.

See Also: ConsiderCustomAccessorsForNonVisibleEventsRule Members

Syntax

[Gendarme.Framework.Problem("The compiler created add/remove event accessors are, by default, synchronized, i.e. the runtime will wrap them inside a Monitor.Enter/Exit.")]
[Gendarme.Framework.Solution("For non-visible events see if your code could work without being synchronized by supplying your own accessor implementations.")]
public class ConsiderCustomAccessorsForNonVisibleEventsRule : Gendarme.Framework.Rule, Gendarme.Framework.ITypeRule

Remarks

This rule is available since Gendarme 2.0

Example

Bad example:

Example

            private event EventHandler<TestEventArgs> TimeCritical;
            

Example

Good example:

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);
            	}
            }
            

Requirements

Namespace: Gendarme.Rules.Performance
Assembly: Gendarme.Rules.Performance (in Gendarme.Rules.Performance.dll)
Assembly Versions: 2.8.0.0