- 162 名前:デフォルトの名無しさん mailto:sage [2012/10/16(火) 17:29:14.42 ]
- 非同期でダウンロードした画像をプロパティを通して渡したい(キャッシュがある場合はキャッシュを返す)
受け取った側はそのままPictureBoxに表示 Imagaで返すのは恐らく無理っぽいからこういう感じのものを作った public static Task<Image> Image 受け取る側はこんな感じにしてみた private void DownloadImage3ByProperty() { TaskScheduler ui = TaskScheduler.FromCurrentSynchronizationContext(); var task = Downloader.Image; task.ContinueWith(t => { pictureBox1.Image = t.Result; },ui); Debug.WriteLine("ここの処理はすぐ実行される"); } わからないのが、Task<Image>をどのように返すか とりあえず、ダウンロードして返す方のプロパティを作ろうとするもののうまくできない public static Task<Image> DownloadImageTaskByProperty(string address, string filename) { Image img = null; Task<Image> ti = new Task<Image>(() => { Task task = WebClientExtensions.DownloadFileTask(new WebClient(), address, filename); task.Wait(); return Bitmap.FromFile(filename); }); ti.Wait();//ここでロックされる Debug.WriteLine("Completed DownloadImageTaskByProperty"); return ti; }
|

|