Previous | Home | Next |
The BackgroundWorker Component allows a form to run an operation asynchronously. This is very useful when we deal with such kind of operations as database transactions, image downloads etc.
Adding DoWork
The DoWork method is like any other event handler. Here we must look at the VB view of your file, where we will see the DoWork method. You should see that the backgroundWorker1_DoWork event is generated when you double-click on DoWork. For testing, let's add a Thread.Sleep command there. The Thread.Sleep method will pause the execution of the BackgroundWorker, but does not consume the entire CPU.
Code For DoWork Event is Given Below
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork Dim argumentTest As TestObject = TryCast(e.Argument, TestObject) Thread.Sleep(100) argumentTest.OneValue = 12 argumentTest.TwoValue = 14 e.Result = argumentTest End Sub
Previous | Home | Next |