title: What is the TPL equivalent of rx's Observable.FromEventPattern?
body: <p>In rx you can write :</p>
  
  <pre><code>var oe = Observable.FromEventPattern&lt;SqlNotificationEventArgs&gt;(sqlDep, "OnChange");
  </code></pre>
  
  <p>and then subscribe to the observable to convert the OnChange event on the sqlDep object into an observable.</p>
  
  <p>Similarily, how can you create a Task from a C# event using the Task Parallel Library ?</p>
  
  <p><strong>EDIT: clarification</strong>
  The solution pointed by Drew and then written explicitely by user375487 works for a single event. As soon as the task finished ... well it is finished.</p>
  
  <p>The observable event is able to trigger again at any time. It is can be seen as an observable stream. A kind of ISourceBlock in the TPL Dataflow. But in the doc <a href="http://msdn.microsoft.com/en-us/library/hh228603(v=vs.110).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/hh228603(v=vs.110).aspx</a> there is no example of ISourceBlock. </p>
  
  <p>I eventually found a forum post explaining how to do that: <a href="http://social.msdn.microsoft.com/Forums/en/tpldataflow/thread/a10c4cb6-868e-41c5-b8cf-d122b514db0e" rel="nofollow">http://social.msdn.microsoft.com/Forums/en/tpldataflow/thread/a10c4cb6-868e-41c5-b8cf-d122b514db0e</a></p>
  
  <p><s>
      public static ISourceBlock CreateSourceBlock(
          Action,Action,Action,ISourceBlock> executor)
      {
          var bb = new BufferBlock();
          executor(t => bb.Post(t), () => bb.Complete(), e => bb.Fault(e), bb);
          return bb;
      }</p>
  
  <pre><code>//Remark the async delegate which defers the subscription to the hot source.
  var sourceBlock = CreateSourceBlock&lt;SomeArgs&gt;(async (post, complete, fault, bb) =&gt;
  {
      var eventHandlerToSource = (s,args) =&gt; post(args);
      publisher.OnEvent += eventHandlerToSource;
      bb.Complete.ContinueWith(_ =&gt; publisher.OnEvent -= eventHandlerToSource);
  });
  </code></pre>
  
  <p>I've not tryed the above code. There may be a mismatch between the async delegate and the definition of CreateSourceBlock.
  </s></p>