private Task<Stream> GetArtistImageTask(ISession session, IArtist artist) { LoginService.EnsureUserIsLoggedIn(); return session .BrowseAsync(artist, ArtistBrowseType.NoTracks | ArtistBrowseType.NoAlbums) .ContinueWith(t => { using (t.Result) { if (t.Result.Portraits.Count > 0) { using (var image = t.Result.Portraits[0]) { if (image.WaitUntilLoaded()) { return new MemoryStream(image.Data); } return new MemoryStream(); } } if (t.Result.Albums.Count > 0) { foreach (var album in t.Result.Albums) { using (album) { if (album.WaitUntilLoaded() && !string.IsNullOrEmpty(album.CoverId)) { return GetImage(album.CoverId); } } } } } return new MemoryStream(); }); }