title: Using yield from an event handler
body: <p>I have a method <code>Foo.LongRunningMethod()</code>, which does some very complicated processing that may go on for a long time. Along the way, it fires <code>Foo.InterestingEvent</code> whenever it encounters a certain condition. I'd like to be able to expose an enumeration of those events, and I'd like to be able to start iterating before <code>LongRunningMethod</code> actually finishes. In other words, what I want is something like this:</p>
  
  <pre><code>public IEnumerable&lt;InterestingObject&gt; GetInterestingObjects()
  {
      foo.InterestingEvent += (obj) =&gt; { yield return obj; }
      foo.LongRunningMethod();
  
      yield break;
  }
  </code></pre>
  
  <p>This doesn't work, though, for the sensible reason that you can't <code>yield return</code> from an anonymous method (and because a method using <code>yield</code> cannot return <code>void</code>, which our event handler does). Is there another idiom that allows me to accomplish this? Or is this just a bad idea?</p>