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 ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.