title: Google Indexing API with Winforms throws a TaskCanceledException
body: <p>I need to integrated Google Indexing API in a Winforms application, but the same code that runs successfully in a MVC web application fails on Winforms throwing a TaskCanceledException after some while.</p>
  <p>I reduced my code to the bare minimum and this is the code that works in a MVC controller:</p>
  <pre><code>public class HomeController : Controller
  {
      public async Task&lt;ActionResult&gt; Index()
      {
          try
          {
              var path = &quot;C:\\delme\\pimpi-339712-a3a8fa51f993.json&quot;; // the private key of my service account owner of the site
              GoogleCredential googleCredential;
              using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
              {
                  googleCredential = GoogleCredential.FromStream(stream).CreateScoped(new[] { &quot;https://www.googleapis.com/auth/indexing&quot; });
              }
  
              var credential = googleCredential.UnderlyingCredential;
              var googleIndexingApiClientService = new IndexingService(new BaseClientService.Initializer
              {
                  HttpClientInitializer = credential
              });
  
              string url = &quot;https://www.pimpmytrip.it/cosa-vedere-madrid-in-3-giorni/&quot;;
              var metaDataRequest = new GetMetadataRequest(googleIndexingApiClientService, url);
  
              var meta = await metaDataRequest.ExecuteAsync();
          }
          catch (Exception ex)
          {
          }
      }
  }
  </code></pre>
  <p>If the same code is used in a Winforms event handler it does NOT work:</p>
  <pre><code>private async void btnVerify_Click(object sender, EventArgs e)
  {
      try
      {
          var path = &quot;C:\\delme\\pimpi-339712-a3a8fa51f993.json&quot;; // the private key of my service account owner of the site
          GoogleCredential googleCredential;
          using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
          {
              googleCredential = GoogleCredential.FromStream(stream).CreateScoped(new[] { &quot;https://www.googleapis.com/auth/indexing&quot; });
          }
  
          var credential = googleCredential.UnderlyingCredential;
          var googleIndexingApiClientService = new IndexingService(new BaseClientService.Initializer
          {
              HttpClientInitializer = credential
          });
  
          string url = &quot;https://www.pimpmytrip.it/cosa-vedere-madrid-in-3-giorni/&quot;;
          var metaDataRequest = new GetMetadataRequest(googleIndexingApiClientService, url);
  
          var meta = await metaDataRequest.ExecuteAsync(); // throws TaskCanceledException
      }
      catch (Exception ex)
      {
      }
  }
  </code></pre>
  <p>What am I missing? Why is it working if I use it in a MVC application and not in a Winforms application?</p>