title: Weak event handler model for use with lambdas
body: <p>OK, so this is more of an answer than a question, but after asking <a href="https://stackoverflow.com/questions/371109/garbage-collection-when-using-anonymous-delegates-for-event-handling">this question</a>, and pulling together the various bits from <a href="http://diditwith.net/CommentView,guid,aacdb8ae-7baa-4423-a953-c18c1c7940ab.aspx#commentstart" rel="nofollow noreferrer">Dustin Campbell</a>, <a href="https://stackoverflow.com/questions/371109/garbage-collection-when-using-anonymous-delegates-for-event-handling/1447619#1447619">Egor</a>, and also one last tip from the '<a href="http://channel9.msdn.com/shows/Going+Deep/Expert-to-Expert-Brian-Beckman-and-Erik-Meijer-Inside-the-NET-Reactive-Framework-Rx/" rel="nofollow noreferrer">IObservable/Rx/Reactive framework</a>', I think I've worked out a workable solution for this particular problem. It may be completely superseded by IObservable/Rx/Reactive framework, but only experience will show that.</p>
  
  <p>I've deliberately created a new question, to give me space to explain how I got to this solution, as it may not be immediately obvious.</p>
  
  <p>There are many related questions, most telling you you can't use inline lambdas if you want to be able to detach them later:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/1089309/weak-events-in-net">Weak events in .Net?</a></li>
  <li><a href="https://stackoverflow.com/questions/859936/unhooking-events-with-lambdas-in-c">Unhooking events with lambdas in C#</a></li>
  <li><a href="https://stackoverflow.com/questions/16473/can-using-lambdas-as-event-handlers-cause-a-memory-leak">Can using lambdas as event handlers cause a memory leak?</a></li>
  <li><a href="https://stackoverflow.com/questions/805829/how-to-unsubscribe-from-an-event-which-uses-a-lambda-expression">How to unsubscribe from an event which uses a lambda expression?</a></li>
  <li><a href="https://stackoverflow.com/questions/183367/unsubscribe-anonymous-method-in-c">Unsubscribe anonymous method in C#</a></li>
  </ul>
  
  <p>And it is true that if <em>YOU</em> want to be able to detach them later, you need to keep a reference to your lambda. However, if you just want the event handler to detach itself when your subscriber falls out of scope, this answer is for you.</p>