I’m programming a application and am wondering, is there a co-routine (or something similar) feature in VB?
In my application it pulls a picture from the internet and it takes quite a long time (30-45 seconds) and it stops all code from running while it does that. Here is the line of codes that pulls that picture:
PictureBox1.Image = Image.FromStream(System.Net.HttpWebRequest.Create("http://www.example.com/avimgs/" & Username.Text & ".gif").GetResponse().GetResponseStream())
The general-purpose method is to create a background thread yourself, as in other answers.
But many .NET components provide a built-in solution for performing their work asynchronously – always easier than manually creating threads. And the PictureBox has support for asynchronous loading of images.
Here is the complete code from the MSDN sample, including error handling, cancelling the download and notification of completion. It couldn’t be easier.