The general task that I have to complete for the site I'm working on is the following:
- Download data from a third-party API
- Process data in some way
- Show results on page
At first I used WebClient.DownloadStringAsync and did my processing on the result. However, I found that DownloadStringAsync does not comply with the AsyncTimeout parameter, which I kind of expected when I read a little about how this works.
I ended up adapting the code using the PageAsyncTask example to use DownloadString () there - note that this is a synchronous version. This is probably good because the task is now asynchronous. Now the tasks are properly exhausted, and I can get the PreRender () time data, and I can easily generalize this and put it on any page, I need this functionality.
However, I'm just worried that this is not "clean." The page will not be notified when the task is completed, as the DownloadStringAsync method does. I just need to scoop up the results (stored in a field in the class) at the end of my PreRender event.
Is there a way to get Webclient Async methods to work with RegisterPageTask or is it a helper class that I can do best?
Notes: No MVC - this is vanilla asp.net 4.0.
Broam source share