private void AsyncPlayFilesWorker(object sender, DoWorkEventArgs e) { var songs = (Collection <ApiAudioSong>)e.Argument; if (songs == null) { return; } if (!_parent.IsConnected()) { return; } var plId = new JsonObject(); plId["playlistid"] = 1; _parent.JsonCommand("Playlist.Clear", plId); var i = 0; var args = new JsonObject(); var items = new JsonObject(); foreach (var apiAudioSong in songs) { if (((BackgroundWorker)sender).CancellationPending) { e.Cancel = true; return; } args["songid"] = apiAudioSong.IdSong; items["item"] = args; items["playlistid"] = 1; _parent.JsonCommand("Playlist.Add", items); if (i != 0) { continue; } var item = new JsonObject(); item["item"] = plId; _parent.JsonCommand("Player.Open", item); i++; } }