[Help] Program hangs when using web requests?[Solved]
I've made a few programs in VB and they always seem to hang whenever I do a download or web request but it does eventually work. Here is an example code:
Code:
Dim URL As String = wc.DownloadString("http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt")
Is there a way to make it not hang or go faster?
Put it in a multithread f.e..
[php]private url as string
Private sub Download()
url = wc.DownloadString("http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt")
'something else...
end sub
[/php]
Form_load or button or whatever.
[php]dim t as new threading.thread(addressof download)
t.start[/php]
You can multithread your program with the code above.
Bleh if you're only doing one thing, just add a backgroundworker control to your form it does the events outside the UI thread so you won't see it hanging. Add the code to the BGW main event (double click the control), and when you want to execute it, simply call it like this:
[php]
BackgroundWorker1. RunWorkerAsync()
[/php]
Cleaner than manually threading IMO.
Yeahs, I solved it yesterday, thanks Blubb, also, I'll keep that in mind Jason!