A little background:
When a hard task comes for a VB.NET application, for example Downloading data off Internet, copying large files, etc.. The application hangs over there without making use of more threads. This hanging problem can be solved to a great extent by using the .NET component called ‘BackgroundWorker’.
The little example below will show you how to use it.
- Drag ‘BackgroundWorker’ from toolbox.
- Drag a button
Double click on form and type:
Public Shared Sub Thread()
Dim dlURL As String
dlURL = “http://example.com/filename.png”
Dim savingpath As String
savingpath = My.Computer.FileSystem.CurrentDirectory.ToString + “file.png”)
Now double click on button and type
What will this example do?
Hmm, it will download the specified file and you will be able to clearly observe that the application does not hang. Run this application and check Network Statistics, the load will be ‘maximum’.