1
我有一個像下面執行的任務與Task.WaitAll掛在C#
public class ImageUploader
{
....
public Task<string> Upload()
{
return new Task<string>(
() =>
{
....
return UploadedFilePath;
}
);
}
....
}
然後我用它像這樣
var uploadIcon = new ImageUploader();
var uploadLogo = new ImageUploader();
var uploadIconTask = uploadIcon.Upload();
var uploadLogoTask = uploadLogo.Upload();
Task.WaitAll(uploadIconTask, uploadLogoTask); // never returns
我和Task.WaitAll掛起永遠一類!
是什麼問題?
對於'async' /'await'你應該使用'Task.Run'。 –