SharkTheDark
SharkTheDark

Reputation: 3119

How to run function in background in VB.NET?

I am developing app in VB.NET that should have HTML requests and getting responses as string.

Now I am using this code:

    Dim URL as String = "http://domain.com/page.php"
    Dim webClient As System.Net.WebClient = New System.Net.WebClient()
    Dim result As String = webClient.DownloadString(URLL)

But when I run this code, my program froze for a little bit, until this URL content is loaded.

I searched over google and I didn't find anything about this. I tried using Classes and Modules, but with both of those it's frizzing again.

Can someone explain me how to run this in background, so program won't froze, and when it get's downloaded to return data?

Thanks.

Upvotes: 1

Views: 28177

Answers (1)

Tim
Tim

Reputation: 28520

I believe what you're looking for is the BackgroundWorker Class. This will allow you to spin the request off on a separate thread without freezing the UI. It's a pretty common thing.

Here's a couple of examples:

VB.NET BackgroundWorker Use

BackgroundWorker Demo

Upvotes: 3

Related Questions