private void Button_Click(object sender, RoutedEventArgs e) { var username = this.Username.Text; var passwrod = this.Password.Password; new Thread(() => { var credentials = new SoundCloudCredentials(ClientId, ClientSecret, username, passwrod); var client = new SoundCloudClient(credentials); SoundCloudAccessToken token = null; try { token = client.Authenticate(); } catch (Exception) { MessageBox.Show("login failed."); return; } var downloader = new Downloader(ClientId, token.AccessToken); //fetch some data if (client.IsAuthenticated) { //Fetch current user info var mySelf = User.Me(); var clientID = client.getClientID(); var trackList = new List <Track>(); var i = 1; var limit = 200; var favorites = User.Me().GetFavorites(limit, 1); while (favorites.NextHref != null) { foreach (var favorite in favorites.Tracks) { var track = Track.GetTrack(favorite.Id); if (downloader.DownloadMusicWithTrackId(track)) { ListView1.Dispatcher.Invoke( new Action(() => { _likeCollection.Add(new Like() { Index = i++, Title = track.Title }); })); } } favorites = JsonSerializer.Deserialize <Favorite>(new WebClient() { Encoding = new UTF8Encoding() }.DownloadString(favorites.NextHref)); } MessageBox.Show("download successfully finished."); } }).Start(); }