public static IAsyncResult Begin(ImageLoad load, IntPtr p, Session session, ImageSize size, AsyncCallback userCallback, object state) { AsyncLoadImageResult result = new AsyncLoadImageResult(userCallback, state); Image image = new Image(LibSpotify.sp_image_create_r(session.Handle, load(p, size))); result.Closure = image; image.Loaded += result.HandleImageLoaded; // It's possible the image loaded before we registered the result.HandleImageLoaded if (image.IsLoaded) { result.CompletedSynchronously = true; result.SetCompleted(image.Error); } return(result); }
public IAsyncResult BeginLoadPortraits(Session session, AsyncCallback userCallback, object state) { ThrowHelper.ThrowIfNull(session, "session"); int n = LibSpotify.sp_artistbrowse_num_portraits_r(Handle); AsyncLoadPortraitsResult result = new AsyncLoadPortraitsResult(n, userCallback, state); result.Closure = new List <Image>(); for (int i = 0; i < n; ++i) { Image image = new Image(LibSpotify.sp_image_create_r(session.Handle, LibSpotify.sp_artistbrowse_portrait_r(Handle, i))); image.Loaded += result.HandleImageLoaded; result.Closure.Add(image); } if (result.CheckComplete()) { result.CompletedSynchronously = true; } return(result); }