title: TaskScheduler.TryExecuteTaskInline - the same thread or context?
body: <p><a href="https://msdn.microsoft.com/en-gb/library/system.threading.tasks.taskscheduler.tryexecutetaskinline(v=vs.110).aspx" rel="nofollow">MSDN documentation of TryExecuteTaskInline</a> states that:</p>
  
  <blockquote>
    <p>A class derived from TaskScheduler implements this function to support
    inline execution of a task on a thread that initiates a wait on that
    task object.</p>
  </blockquote>
  
  <p>However, if you look in the <a href="http://referencesource.microsoft.com/#mscorlib/system/threading/Tasks/TaskScheduler.cs" rel="nofollow">source code</a>, the implementation of <code>TaskScheduler.TryExecuteTaskInline</code>:</p>
  
  <pre><code>protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
  {
      if (SynchronizationContext.Current == m_synchronizationContext)
      {
          return TryExecuteTask(task);
      }
      else
          return false;
  }
  </code></pre>
  
  <p>only checks if the current synchronization context is the same as one captured during the instantiation (see the <code>SynchronizationContextTaskScheduler</code> constructor in the same source file). Multiple threads can share one synchronization context, so it doesn't necessarily mean the same thread.</p>
  
  <p>So it's either than I don't actually understand what the documentation says, or it's wrong. Could anyone explain that?</p>
  
  <p>I just can't see how this implementation 'supports inline execution of a task on a thread that initiates a wait on that task object.', as required by documentation of that method. It just calls TryExecuteTask, which calls task's ExecuteEntry (you can just click on the method name to jump to its source).</p>