What do you call asynchronous web request in VB.NET?

I am currently using the following code to create a web request:

Dim myRequest As WebRequest = WebRequest.Create("http://foo.com/bar")
Dim myResponse As WebResponse = myRequest.GetResponse()

The problem is that it “blocks” the program until the request completes (and the program freezes if the request never completes). How do I change something like this to execute asynchronously so that other tasks can be completed during the completion of the web request?

+3
source share
2 answers

You will use BeginGetResponse to add AsyncCallback, which basically points to some other method in your code that will be called when WebRequest returns. There is a good example here .

http://www.sitepoint.com/forums/showpost.php?p=3753215

+3

myRequest.BeginGetResponse()

EndGetReponse(), ( WaitHandle, callback ).

0

Source: https://habr.com/ru/post/1697473/


All Articles