title: How to convert code YouTube API from Console to WPF
body: <p>I have code worked fine in Console but i tried convert it to WPF c# but i didn't success.
  I tried porting each part to WPF and I found out the code below (2nd code I quoted below) when I convert it to WPF it doesn't work
  Please help me. How to it work fine in WPF c#
  This is my code:</p>
  <blockquote>
  <pre><code>    using System;
      using System.Collections.Generic;
      using System.IO;
      using System.Linq;
      using System.Reflection;
      using System.Threading;
      using System.Threading.Tasks;
      
      using Google.Apis.Auth.OAuth2;
      using Google.Apis.Services;
      using Google.Apis.Upload;
      using Google.Apis.Util.Store;
      using Google.Apis.YouTube.v3;
      using Google.Apis.YouTube.v3.Data;
      
      namespace ConsoleApp2
      {
          
          internal class PlaylistUpdates
          {
              public string PrivacyStatus { get; private set; }
      
              [STAThread]
              static void Main(string[] args)
              {
                  Console.WriteLine(&quot;YouTube Data API: Playlist Updates&quot;);
                  Console.WriteLine(&quot;==================================&quot;);
      
                  try
                  {
                       //new PlaylistUpdates().Run().Wait();
                      //new PlaylistUpdates().RunUpload().Wait();
                      new PlaylistUpdates().Editvideo().Wait();
                      
                  }
                  catch (AggregateException ex)
                  {
                      foreach (var e in ex.InnerExceptions)
                      {
                          Console.WriteLine(&quot;Error: &quot; + e.Message);
                      }
                  }
      
                  Console.WriteLine(&quot;Press any key to continue...&quot;);
                  Console.ReadKey();
              }
  
              private async Task Editvideo()
              {
                  UserCredential credential;
                  using (var stream = new FileStream(&quot;client_secrets.json&quot;, FileMode.Open, FileAccess.Read))
                  {
                      credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                          GoogleClientSecrets.Load(stream).Secrets,
                          // This OAuth 2.0 access scope allows for read-only access to the authenticated 
                          // user's account, but not other types of account access.
                          new[] { YouTubeService.Scope.YoutubeReadonly },
                          &quot;user&quot;,
                          CancellationToken.None,
                          new FileDataStore(this.GetType().ToString())
                      );
                  }
      
                  var youtubeService = new YouTubeService(new BaseClientService.Initializer()
                  {
                      HttpClientInitializer = credential,
                      ApplicationName = this.GetType().ToString()
                  });
      
                  var channelsListRequest = youtubeService.Channels.List(&quot;contentDetails&quot;);
                  channelsListRequest.Mine = true;
      
                  // Retrieve the contentDetails part of the channel resource for the authenticated user's channel.
                  var channelsListResponse = await channelsListRequest.ExecuteAsync();
      
                  foreach (var channel in channelsListResponse.Items)
                  {
                      // From the API response, extract the playlist ID that identifies the list
                      // of videos uploaded to the authenticated user's channel.
                      var uploadsListId = channel.ContentDetails.RelatedPlaylists.Uploads;
      
                      Console.WriteLine(&quot;Videos in list {0}&quot;, uploadsListId);
      
                      var nextPageToken = &quot;&quot;;
                      while (nextPageToken != null)
                      {
                          var playlistItemsListRequest = youtubeService.PlaylistItems.List(&quot;snippet,status&quot;);
                          playlistItemsListRequest.PlaylistId = uploadsListId;
                          playlistItemsListRequest.MaxResults = 50;
                          playlistItemsListRequest.PageToken = nextPageToken;
      
                          // Create a new, private playlist in the authorized user's channel.
                          var newVideo = new Video();
                          newVideo.Snippet = new VideoSnippet();
                          newVideo.Id = &quot;6obQQde1X3A&quot;;
                          newVideo.Snippet.Title = &quot;My Title&quot;;
                          newVideo.Snippet.Description = &quot;My Description&quot;;
                          newVideo.Snippet.Tags = new string[] { &quot;tag 1&quot;, &quot;tag 2&quot;, &quot;tag 3&quot; };
                          newVideo.Snippet.CategoryId = &quot;22&quot;;
                          newVideo.Status = new VideoStatus();
                          newVideo.Status.PrivacyStatus = &quot;public&quot;;
                          newVideo = await youtubeService.Videos.Update(newVideo,&quot;Id,snippet,status&quot;).ExecuteAsync();
      
                          Console.WriteLine(&quot;Change video details OK ....&quot;);
       
                          // Retrieve the list of videos uploaded to the authenticated user's channel.
                          var playlistItemsListResponse = await playlistItemsListRequest.ExecuteAsync();
      
                          foreach (var playlistItem in playlistItemsListResponse.Items)
                          {
                          Console.WriteLine(&quot;{0} ({1})&quot;, playlistItem.Snippet.Title, playlistItem.Snippet.ResourceId.VideoId);
                          }
      
                          nextPageToken = playlistItemsListResponse.NextPageToken;
                      }
                  }
              }
      }
      
      }
  </code></pre>
  </blockquote>
  <p>If i remove this code below. It worked fine!</p>
  <pre><code>// Create a new, private playlist in the authorized user's channel.
                          var newVideo = new Video();
                          newVideo.Snippet = new VideoSnippet();
                          newVideo.Id = &quot;6obQQde1X3A&quot;;
                          newVideo.Snippet.Title = &quot;My Title&quot;;
                          newVideo.Snippet.Description = &quot;My Description&quot;;
                          newVideo.Snippet.Tags = new string[] { &quot;tag 1&quot;, &quot;tag 2&quot;, &quot;tag 3&quot; };
                          newVideo.Snippet.CategoryId = &quot;22&quot;;
                          newVideo.Status = new VideoStatus();
                          newVideo.Status.PrivacyStatus = &quot;public&quot;;
                          newVideo = await youtubeService.Videos.Update(newVideo,&quot;Id,snippet,status&quot;).ExecuteAsync();
      
                          Console.WriteLine(&quot;Change video details OK ....&quot;);
  </code></pre>
  <p>This is my code in WPF</p>
  <pre><code> private async Task Change_VideoDetails()
      {
          UserCredential credential;
          using (var stream = new FileStream(&quot;client_secrets.json&quot;, FileMode.Open, FileAccess.Read))
          {
              credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                  GoogleClientSecrets.Load(stream).Secrets,
                  new[] { YouTubeService.Scope.YoutubeReadonly },
                  &quot;user&quot;,
                  CancellationToken.None,
                  new FileDataStore(this.GetType().ToString())
              );
          }
  
          var youtubeService = new YouTubeService(new BaseClientService.Initializer()
          {
              HttpClientInitializer = credential,
              ApplicationName = this.GetType().ToString()
          });
          var channelsListRequest = youtubeService.Channels.List(&quot;contentDetails&quot;);
          channelsListRequest.Mine = true;
          // Retrieve the contentDetails part of the channel resource for the authenticated user's channel.
          var channelsListResponse = await channelsListRequest.ExecuteAsync();
  
          foreach (var channel in channelsListResponse.Items)
          {
              // From the API response, extract the playlist ID that identifies the list
              // of videos uploaded to the authenticated user's channel.
              var uploadsListId = channel.ContentDetails.RelatedPlaylists.Uploads;
  
              //Console.WriteLine(&quot;Videos in list {0}&quot;, uploadsListId);
  
              var nextPageToken = &quot;&quot;;
              while (nextPageToken != null)
              {
                  var playlistItemsListRequest = youtubeService.PlaylistItems.List(&quot;Id,snippet,status&quot;);
                  playlistItemsListRequest.PlaylistId = uploadsListId;
                  playlistItemsListRequest.MaxResults = 50;
                  playlistItemsListRequest.PageToken = nextPageToken;
  
                   var newVideo = new Video();
                  newVideo.Snippet = new VideoSnippet();
                  newVideo.Id = &quot;6obQQde1X3A&quot;;
                  txtLog.AppendText(&quot;\nWill change video details.....&quot; + newVideo.Id + );
                  txtLog.ScrollToEnd();
  
                  newVideo.Snippet = new VideoSnippet();
                  newVideo.Id = &quot;6obQQde1X3A&quot;;
                  newVideo.Snippet.Title = &quot;My Title&quot;;
                  newVideo.Snippet.Description = &quot;My Description&quot;;
                  newVideo.Snippet.Tags = new string[] { &quot;tag 1&quot;, &quot;tag 2&quot;, &quot;tag 3&quot; };
                  newVideo.Snippet.CategoryId = &quot;22&quot;;
                  newVideo.Status = new VideoStatus();
                  newVideo.Status.PrivacyStatus = &quot;public&quot;;
                  newVideo = await youtubeService.Videos.Update(newVideo, &quot;Id,snippet,status&quot;).ExecuteAsync();
  
                  txtLog.AppendText(&quot;\nChanged video details .....&quot; + newVideo.Id);
                  txtLog.ScrollToEnd();
  
                  // Retrieve the list of videos uploaded to the authenticated user's channel.
                  var playlistItemsListResponse = await playlistItemsListRequest.ExecuteAsync();
                  int line_count=0;
                  foreach (var playlistItem in playlistItemsListResponse.Items)
                  {
                      
                      line_count += 1;
                      if (line_count == int.Parse(txtVideonumber.Text))
                      {
                          break;
                      }
  
  
                      //}   
  
                  }
  
                  nextPageToken = playlistItemsListResponse.NextPageToken;
              }
          }
      }
  </code></pre>
  <p>I used below code for run above code:</p>
  <pre><code>private void BtnChange_Click(object sender, RoutedEventArgs e)
      {
          Change_VideoDetails();
      }
  </code></pre>
  <p>I tried run debugger and my code is stopping at bellow code:</p>
  <pre><code> newVideo = await youtubeService.Videos.Update(newVideo, &quot;Id,snippet,status&quot;).ExecuteAsync();
  </code></pre>
  <p>I don't understand why it is stopping? Please help me solve it</p>