O'Reilly logo

Visual Basic 2008 Recipes: A Problem-Solution Approach by Rakesh Rajan, Matthew MacDonald, Allen Jones, Todd Herman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4.3. Creating an Asynchronous Method to Update the User Interface

Problem

You need to execute, in a Windows Forms application, some method asynchronously that needs to be able to safely manipulate the user interface.

Solution

Create an instance of the System.ComponentModel.BackgroundWorker class. Perform the asynchronous action within the DoWork event handler, which is raised when you call the BackgroundWorker. RunWorkerAsync method. To allow the asynchronous method to safely interact with the user interface, include a call to the ReportProgress method (within the DoWork event handler), and handle the ProgressChanged event that it raises.

How It Works

The standard process for executing methods asynchronously is to use delegates to interact with ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required