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#!