title: How to avoid Safe handle has been closed
body: <p>I have the following code in a test:</p>
  <pre><code> private void LoadIncomeStatementViewModel()
      {
          using (var evt = new AutoResetEvent(false))
          {
              EventHandler handler = (sender, e) =&gt; evt.Set();
  
              _incomeStatementViewModel.Loaded -= handler;
              _incomeStatementViewModel.Loaded += handler;
              _incomeStatementViewModel.LoadDataCommand.Execute(null);
              evt.WaitOne();
          }
      }
  </code></pre>
  <p>Now if I run the following test</p>
  <pre><code>[Test]
  public void Test()
  {
     LoadIncomeStatementViewModel();
     // do something
  
     LoadIncomeStatementViewModel();
     // do something
  }
  </code></pre>
  <p>The second time the LoadIncomeStatementViewModel() is called I get a &quot;Safe handle has been disposed&quot; error message at
  EventHandler handler = (sender, e) =&gt; evt.Set();</p>
  <p>Surely the using statement has reinitialized evt when the method is rerun the second time. I have a feeling that this may be something to do with the Resharper Test Runner (Nunit 2.7).</p>