ASP.NET MVC 4 Recipes: A Problem-Solution Approach by John Ciliberti

ASP.NET MVC 4 Recipes: A Problem-Solution Approach by John Ciliberti

Author:John Ciliberti
Language: eng
Format: mobi, pdf
Tags: Web, Computers, Programming, Microsoft Programming, Web Programming
ISBN: 9781430247739
Publisher: Apress
Published: 2013-02-19T18:30:00+00:00


Listing 8-5. Using Task.WhenAll with Tasks with Different Return Types

public async Task<ActionResult> GetPhotoAndComments()

{

List<Task> tasks = new List<Task>();

using (WebClient webClient = new WebClient())

{

Uri uri1 = new Uri(PhotoCommentServiceURL);

tasks.Add(webClient.DownloadStringTaskAsync(uri1));

}

using (WebClient webClient = new WebClient())

{

Uri uri2 = new Uri(DynamicImgServiceUrl);

tasks.Add(webClient.DownloadDataTaskAsync(uri2));

}

await Task.WhenAll(tasks);

ViewBag.PhotoComments = ((Task<string>)tasks[0]).Result;

string imageBase64 = Convert.ToBase64String(((Task<byte[]>)tasks[1]).Result);

string imageSrc = string.Format("data:image/jpeg;base64,{0}", imageBase64);

ViewBag.Photo = imageSrc;



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.