title: Is there any way to use Google Calendar API in C# (WPF) with an async method?
body: <p>I am a beginer, this is the example from Google on how to officially implement the Google Calendar API using C#. The problem i have is that there is now way to use it with await/async, which means that my WPF application gets frozen when the requests gets made (?). I have looked on google for answers but could not find anything related to that specific issue.</p>
  <pre><code>using Google.Apis.Auth.OAuth2;
  using Google.Apis.Calendar.v3;
  using Google.Apis.Calendar.v3.Data;
  using Google.Apis.Services;
  using Google.Apis.Util.Store;
  using System;
  using System.Collections.Generic;
  using System.IO;
  using System.Linq;
  using System.Text;
  using System.Threading;
  using System.Threading.Tasks;
  
  namespace CalendarQuickstart
  {
      class Program
      {
          // If modifying these scopes, delete your previously saved credentials
          // at ~/.credentials/calendar-dotnet-quickstart.json
          static string[] Scopes = { CalendarService.Scope.CalendarReadonly };
          static string ApplicationName = &quot;Google Calendar API .NET Quickstart&quot;;
  
          static void Main(string[] args)
          {
              UserCredential credential;
  
              using (var stream =
                  new FileStream(&quot;credentials.json&quot;, FileMode.Open, FileAccess.Read))
              {
                  // The file token.json stores the user's access and refresh tokens, and is created
                  // automatically when the authorization flow completes for the first time.
                  string credPath = &quot;token.json&quot;;
                  credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                      GoogleClientSecrets.Load(stream).Secrets,
                      Scopes,
                      &quot;user&quot;,
                      CancellationToken.None,
                      new FileDataStore(credPath, true)).Result;
                  Console.WriteLine(&quot;Credential file saved to: &quot; + credPath);
              }
  
              // Create Google Calendar API service.
              var service = new CalendarService(new BaseClientService.Initializer()
              {
                  HttpClientInitializer = credential,
                  ApplicationName = ApplicationName,
              });
  
              // Define parameters of request.
              EventsResource.ListRequest request = service.Events.List(&quot;primary&quot;);
              request.TimeMin = DateTime.Now;
              request.ShowDeleted = false;
              request.SingleEvents = true;
              request.MaxResults = 10;
              request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;
  
              // List events.
              Events events = request.Execute();
              Console.WriteLine(&quot;Upcoming events:&quot;);
              if (events.Items != null &amp;&amp; events.Items.Count &gt; 0)
              {
                  foreach (var eventItem in events.Items)
                  {
                      string when = eventItem.Start.DateTime.ToString();
                      if (String.IsNullOrEmpty(when))
                      {
                          when = eventItem.Start.Date;
                      }
                      Console.WriteLine(&quot;{0} ({1})&quot;, eventItem.Summary, when);
                  }
              }
              else
              {
                  Console.WriteLine(&quot;No upcoming events found.&quot;);
              }
              Console.Read();
  
          }
      }
  }
  </code></pre>
  <p>I would need to add await/async but of course it doesn't work event if i make the method async and make it return a task because service.Events.List does not implemet GetAwaiter:</p>
  <pre><code>EventsResource.ListRequest request = await service.Events.List(&quot;primary&quot;); // this is what i would need
  </code></pre>
  <p>I guess the alternative would be to use the pure REST api but is there really no other way?</p>