View Single Post
  #1 (permalink)  
Old April 8th, 2013, 10:25 PM
scarfinv scarfinv is offline
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 5: Asynchronous Development Platform

I'm working through this book, doing the exercises in VB instead of C#.

I'm in Chapter 5, and have reached the section called Implementing Cancellation in C# 5.0.

I'm finding it difficult, since it is talking about creating a CancellationTokenSource object, and then passing its token to the await wc.DownloadStringTaskAsync method. (wc is a WebClient object).

When trying to write the code (in VB), the DownloadStringTaskAsync method doesn't accept a second parameter at all.

I was able to get cancellation working by simply calling the wc.CancelAsync method from inside btn_Cancel_Click.

However, the next step on (page 149, step 8) is then to implement a timeout. It appears that now I really do need to use a CancellationTokenSource object, but I have no idea how to do this, given that I can't associate it with my DownloadStringTaskAsync (or at least not the way the book says to do it)?

Any help would be welcome! Even better if from a VB perspective, rather than C#!