title: How do I listen to TPL TaskStarted/TaskCompleted ETW events
body: <p>I am interested in listening to ETW (event tracing for Windows) TPL events, in particular I'd like to know when a <code>Task</code> starts and when it stops.</p>
  
  <p>Here's a sample program I've used for testing:</p>
  
  <pre><code>   using System;
     using System.Collections.Generic;
     using System.Diagnostics.Tracing;
     using System.Linq;
     using System.Text;
     using System.Threading;
     using System.Threading.Tasks;
  
     namespace ConsoleApplication10
     {
        class Listener : EventListener
        {
           private static readonly Guid tplGuid = new Guid("2e5dba47-a3d2-4d16-8ee0-6671ffdcd7b5");
  
           protected override void OnEventSourceCreated(EventSource eventSource)
           {
              Console.WriteLine("Got guid: " + eventSource.Guid);
              EnableEvents(eventSource, EventLevel.LogAlways);
           }
  
           protected override void OnEventWritten(EventWrittenEventArgs eventData)
           {
              Console.WriteLine("Event: " + eventData.EventId);
           }
        }
  
        class Program
        {
           static void Main(string[] args)
           {
              using (var listener = new Listener())
              {
                 Action doIt = null;
                 doIt = () =&gt;
                 {
                    Thread.Sleep(1000);
                    Console.Write('.');
                    Task.Run(doIt);
                 };
                 Task.Run(doIt);
  
                 Parallel.Invoke(() =&gt; Console.WriteLine("invoke"));
  
                 Console.Read();
              }
           }
        }
     }
  </code></pre>
  
  <p>Sample output is as follows on my machine:</p>
  
  <pre><code>Got guid: 8e9f5090-2d75-4d03-8a81-e5afbf85daf1
  Got guid: 2e5dba47-a3d2-4d16-8ee0-6671ffdcd7b5
  Event: 3
  invoke
  Event: 4
  .......
  </code></pre>
  
  <p>So the Invoke method causes an event to fire, yet the Tasks fire none. Looking at the Task source (e.g. <a href="http://referencesource.microsoft.com/#mscorlib/system/threading/Tasks/Task.cs,2812" rel="noreferrer" title="Task.cs">reference source</a>) the code appears no different from how the <code>Parallel.Invoke</code> event fires.</p>
  
  <p>What is wrong with the above, or, how do I listen to TaskStarted and TaskCompleted events (or <em>any</em> Task related event for that matter)?</p>