C#, C♯, C#相談室 Part76
■ このスレッドは過去ログ倉庫に格納されています
0162デフォルトの名無しさん
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;
}
■ このスレッドは過去ログ倉庫に格納されています