c# - Async CTP - Task timeout question -


i'm reading through tap whitepaper, , confused sample given implementing timeout on page 22:

"consider ui application wants download image , disable ui while image downloading. if download takes long, however, ui should re-enabled , download should discarded."

public async void btndownload_click(object sender, eventargs e) {     btndownload.enabled = false;     try     {         task<bitmap> download = getbitmapasync(url);         if (download == await task.whenany(download, task.delay(3000)))         {             bitmap bmp = await download.timeoutafter(3000);             picturebox.image = bmp;             status.text = “downloaded”;         }         else         {             picturebox.image = null;             status.text = “timed out”;             download.continuewith(t => trace(“task completed”));         }     }     { btndownload.enabled = true; } } 

what confuses me line:

bitmap bmp = await download.timeoutafter(3000); 

what point of timeoutafter @ point in logic? shouldn't have been accomplished via call task.whenany? seems saying is, "after download task has finished, give 3 more seconds finish." error in example or misunderstanding it?

if task.whenany returns "download" means getbitmapasync returned without timing out.

the "await download.timeoutafter(3000)" ensures getting value out of task doesn't take long. doesn't give additional 3s.

it seem difficult imagine how getting result after task completes take long time.

it replaced with:

bitmap bmp = download.value; 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -