﻿<?xml version="1.0" encoding="utf-8"?><Type Name="DoNotUseLockedRegionOutsideMethodRule" FullName="Gendarme.Rules.Concurrency.DoNotUseLockedRegionOutsideMethodRule"><TypeSignature Language="C#" Value="public class DoNotUseLockedRegionOutsideMethodRule : Gendarme.Framework.Rule, Gendarme.Framework.IMethodRule" /><TypeSignature Language="ILAsm" Value=".class public auto ansi beforefieldinit DoNotUseLockedRegionOutsideMethodRule extends Gendarme.Framework.Rule implements class Gendarme.Framework.IMethodRule, class Gendarme.Framework.IRule" /><AssemblyInfo><AssemblyName>Gendarme.Rules.Concurrency</AssemblyName><AssemblyVersion>4.2.0.0</AssemblyVersion></AssemblyInfo><Base><BaseTypeName>Gendarme.Framework.Rule</BaseTypeName></Base><Interfaces><Interface><InterfaceName>Gendarme.Framework.IMethodRule</InterfaceName></Interface></Interfaces><Attributes><Attribute><AttributeName>Gendarme.Framework.EngineDependency(typeof(Gendarme.Framework.Engines.OpCodeEngine))</AttributeName></Attribute><Attribute><AttributeName>Gendarme.Framework.Problem("This method uses Thread.Monitor.Enter() but doesn't use Thread.Monitor.Exit().")</AttributeName></Attribute><Attribute><AttributeName>Gendarme.Framework.Solution("Prefer the lock{} statement when using C# or redesign the code so that Monitor.Enter and Exit are called together.")</AttributeName></Attribute></Attributes><Docs><summary>
             This rule will fire if a method calls <c>System.Threading.Monitor.Enter</c>, 
             but not <c>System.Threading.Monitor.Exit</c>. This is a bad idea for public
             methods because the callers must (indirectly) manage a lock which they do not
             own. This increases the potential for problems such as dead locks because 
             locking/unlocking may not be done together, the callers must do the unlocking
             even in the presence of exceptions, and it may not be completely clear that
             the public method is acquiring a lock without releasing it.
            
             This is less of a problem for private methods because the lock is managed by
             code that owns the lock. So, it's relatively easy to analyze the class to ensure
             that the lock is locked and unlocked correctly and that any invariants are 
             preserved when the lock is acquired and after it is released. However it is
             usually simpler and more maintainable if methods unlock whatever they lock.
             </summary><remarks>To be added.</remarks><example>
             Bad example:
             <code>
             class BadExample {
             	int producer = 0;
             	object lock = new object();
            
             	// This class is meant to be thread safe, but in the interests of
             	// performance it requires clients to manage its lock. This allows
             	// clients to grab the lock, batch up edits, and release the lock
             	// when they are done. But this means that the clients must
             	// now (implicitly) manage the lock which is problematic, especially
             	// if this object is shared across threads.
             	public void BeginEdits ()
             	{
            		Monitor.Enter (lock);
            	}
            
             	public void AddProducer ()
             	{
             		// Real code would either assert or throw if the lock is not held. 
            		producer++;
            	}
            
             	public void EndEdits ()
             	{
            		Monitor.Exit (lock);
            	}
             }
             </code></example><example>
             Good example:
             <code>
             class GoodExample {
             	int producer = 0;
             	object mutex = new object();
            	
            	public void AddProducer ()
            	{
             		// We need a try block in case the assembly is compiled with
             		// checked arithmetic.
            		Monitor.Enter (mutex);
             		try {
            			producer++;
             		}
            		finally {
            			Monitor.Exit (mutex);
             		}
            	}
            	
            	public void AddProducer2 ()
            	{
             		// Same as the above, but with C# sugar.
            		lock (mutex) {
            			producer++;
             		}
            	}
             }
             </code></example></Docs><Members><Member MemberName=".ctor"><MemberSignature Language="C#" Value="public DoNotUseLockedRegionOutsideMethodRule ();" /><MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor() cil managed" /><MemberType>Constructor</MemberType><AssemblyInfo><AssemblyVersion>4.2.0.0</AssemblyVersion></AssemblyInfo><Parameters /><Docs><summary>To be added.</summary><remarks>To be added.</remarks></Docs></Member><Member MemberName="CheckMethod"><MemberSignature Language="C#" Value="public Gendarme.Framework.RuleResult CheckMethod (Mono.Cecil.MethodDefinition method);" /><MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance valuetype Gendarme.Framework.RuleResult CheckMethod(class Mono.Cecil.MethodDefinition method) cil managed" /><MemberType>Method</MemberType><AssemblyInfo><AssemblyVersion>4.2.0.0</AssemblyVersion></AssemblyInfo><ReturnValue><ReturnType>Gendarme.Framework.RuleResult</ReturnType></ReturnValue><Parameters><Parameter Name="method" Type="Mono.Cecil.MethodDefinition" /></Parameters><Docs><param name="method">To be added.</param><summary>To be added.</summary><returns>To be added.</returns><remarks>To be added.</remarks></Docs></Member><Member MemberName="Initialize"><MemberSignature Language="C#" Value="public override void Initialize (Gendarme.Framework.IRunner runner);" /><MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance void Initialize(class Gendarme.Framework.IRunner runner) cil managed" /><MemberType>Method</MemberType><AssemblyInfo><AssemblyVersion>4.2.0.0</AssemblyVersion></AssemblyInfo><ReturnValue><ReturnType>System.Void</ReturnType></ReturnValue><Parameters><Parameter Name="runner" Type="Gendarme.Framework.IRunner" /></Parameters><Docs><param name="runner">To be added.</param><summary>To be added.</summary><remarks>To be added.</remarks></Docs></Member></Members></Type>