public Task ShowThumbnailAsync(PostClass post) { this.CancelAsync(); this.scrollBar.Enabled = false; this.cancelTokenSource = new CancellationTokenSource(); var cancelToken = this.cancelTokenSource.Token; this.task = Task.Factory.StartNew(() => ThumbnailGenerator.GetThumbnails(post), cancelToken) .ContinueWith( /* await使いたい */ t => { var thumbnails = t.Result; this.SetThumbnailCount(thumbnails.Count); if (thumbnails.Count == 0) { return; } for (int i = 0; i < thumbnails.Count; i++) { var thumb = thumbnails[i]; var picbox = this.pictureBox[i]; picbox.Tag = thumb; picbox.LoadAsync(thumb.ThumbnailUrl); var tooltipText = thumb.TooltipText; if (!string.IsNullOrEmpty(tooltipText)) { this.toolTip.SetToolTip(picbox, tooltipText); } cancelToken.ThrowIfCancellationRequested(); } this.pictureBox[0].Visible = true; this.scrollBar.Maximum = thumbnails.Count - 1; if (thumbnails.Count > 1) { this.scrollBar.Enabled = true; } if (this.ThumbnailLoading != null) { this.ThumbnailLoading(this, new EventArgs()); } }, cancelToken, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.FromCurrentSynchronizationContext() ); return(this.task); }
protected virtual List <ThumbnailInfo> GetThumbailInfo(PostClass post) { return(ThumbnailGenerator.GetThumbnails(post)); }