If I have the following code:
public class Foo
{
public void Bar()
{
var someTypeWithAnEvent = new SomeTypeWithAnEvent();
using (var signal = new ManualResetEvent(false))
{
someTypeWithAnEvent.Begun += (sender, e) => signal.Set();
someTypeWithAnEvent.Begin();
signal.WaitOne();
}
}
}
FxCop seems to throw a CA1001 error:
CA1001 : Microsoft.Design : Implement IDisposable on 'Foo' because it creates members of the following IDisposable types: 'ManualResetEvent'.
This doesn't seem valid in this instance because I'm disposing of the ManualResetEvent
through the using
block.
Am I missing something here or is there an error in the rule?