Async CTP - task timeout task

I am reading a TAP Whitepaper , and I am confused by this sample given to implement the timeout on page 22:

“Consider a user interface application that wants to download an image and disable the interface when loading the image. However, if the download takes too much time, the user interface must be turned on again and the download should be dropped.”

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 finally completed"));
        }
    }
    finally { btnDownload.Enabled = true; }
}

What confuses me this line:

Bitmap bmp = await download.TimeoutAfter(3000);

What is the meaning of TimeoutAfter at this point in logic? Wasn’t this already done by calling Task.WhenAny? This seems to be what he says: "After the download task is finished, give it another 3 seconds." Is this a mistake in the example, or do I not understand it?

+5
1

Task.WhenAny "", , GetBitmapAsync .

" download.TimeoutAfter(3000)" , . 3s.

, , .

:

Bitmap bmp = download.Value;
+3

All Articles