title: How does Task.CurrentId work?
body: <p>I am currently learning how to use Tasks, async and await in Windows Store ("Metro") apps. I stumbled upon the property <code>Task.CurrentId</code> and try to understand how it works.</p>
  
  <p>According to <a href="http://msdn.microsoft.com/en-us/library/system.threading.tasks.task.currentid.aspx" rel="noreferrer">MSDN</a> it returns <em>"An integer that was assigned by the system to the currently-executing task"</em>. So I added logging this value to my custom logger, but to my surprise none of my test apps ever logged anything but <code>null</code>.</p>
  
  <p>Look at this example:</p>
  
  <pre><code>private async void TestButton_Click(object sender, RoutedEventArgs e)
  {
      int? id1 = Task.CurrentId;
  
      await Task.Delay(100);
      int? id2 = Task.CurrentId;
  
      StorageFolder folder = ApplicationData.Current.LocalFolder;
      StorageFile file = await folder.CreateFileAsync("test.txt", 
          CreationCollisionOption.OpenIfExists);
      int? id3 = Task.CurrentId;
  
      await FileIO.AppendTextAsync(file, "test");
      int? id4 = Task.CurrentId;
  
      await DoMoreAsync();
      int? id7 = Task.CurrentId;
  }
  
  private async Task DoMoreAsync()
  {
      StorageFolder folder = ApplicationData.Current.LocalFolder;
      StorageFile file = await folder.CreateFileAsync("test.txt",
          CreationCollisionOption.OpenIfExists);
      int? id5 = Task.CurrentId;
  
      await FileIO.AppendTextAsync(file, "test");
      int? id6 = Task.CurrentId;
  }
  </code></pre>
  
  <p>All these ids are <code>null</code>. Why? This code does create tasks, doesn't it? Shouldn't they have an id?</p>