title: Task FromResult vs TaskCompletionSource SetResult
body: <p>What is the difference <strong>concerning</strong> the functionality and meaning of the </p>
  
  <p>TaskCompletionSource + SetResult <strong>vs</strong> Task + FromResult</p>
  
  <p>in the SendAsync method?</p>
  
  <pre><code>protected override Task&lt;HttpResponseMessage&gt; SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
  {
      if (request.RequestUri.Scheme != Uri.UriSchemeHttps)
      {
          var response = new HttpResponseMessage(HttpStatusCode.Forbidden) {ReasonPhrase = "HTTPS Required"};
          var taskCompletionSource = new TaskCompletionSource&lt;HttpResponseMessage&gt;();
          taskCompletionSource.SetResult(response);
          return taskCompletionSource.Task;
      }
      return base.SendAsync(request, cancellationToken);
  }
  
  protected override Task&lt;HttpResponseMessage&gt; SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
  {
      if (!request.RequestUri.Scheme.Equals(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase))
      {
          HttpResponseMessage reply = request.CreateErrorResponse(HttpStatusCode.BadRequest, "HTTPS is required for security reason.");
          return Task.FromResult(reply);
      }
  
      return base.SendAsync(request, cancellationToken);
  }
  </code></pre>