|
-
Dec 1st, 2011, 09:56 PM
#1
Thread Starter
Lively Member
WebClient Async
I am trying to get my program to read async so it doesn't just freeze up while it fetches the data. I have:
Code:
SR = New StreamReader(WC.OpenReadAsync(New Uri(url)))
Dim html = SR.ReadToEnd.ToString
It keeps throwing the error "does not produce an expression". I remember trying this in the past, only to have the same error. I tried giving the online syntax guide a look, but don't find a mistake on my part (although I know i'm not doing something right).
-
Dec 1st, 2011, 10:25 PM
#2
Re: WebClient Async
How would that code work? You want the WebClient to work asynchronously but you have a StreamReader sitting their waiting for its result, so what use would that be? I don't think you have looked at any examples or read the documentation at all. This is from the documentation:
This method retrieves a Stream instance used to access the resource specified by the address parameter. The stream is obtained using thread resources that are automatically allocated from the thread pool. To receive notification when the stream is available, add an event handler to the OpenReadCompleted event.
So, you handle that event and, in the event handler, you'll get the Stream, which you can then pass to the StreamReader, which you create in the event handler.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|