Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Await and WebClient

$
0
0

WebClient has "Async" methods and I am wondering if it is possible to use Await with them.  I need to improve the responsiveness of an existing program which already uses WebClient.  And I'd rather not disrupt the code by switching to another web accessing class.

I thought I'd begin with a function which looks like this ...

Public Function GetWebPage(ByRef url As String) As String

       Dim wc As New WebClient
            
       Text2Return = wc.DownloadString(url)

Of course there is a lot of other code but that's the essence of it.  I am not sure if it is the right syntax but I'd like to make that last statement something like:  Text2Return = Await wc.DownloadStringAsync(url)

BUT ... 1) the doc for WebClient.DownloadStringAsync does not suggest that it can be used with Await; and 2) as soon as I add Async to my Function statement, which I think I have to do to use Await within the Function, Intellisense gets quite upset.  

I've written a lot of multi-threaded code but in mainframe assembler and I am finding it difficult to wrap my mind around the .Net Async/Await constructs.

Thanks,  Bob


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>