Multithreading Sample

To get samples and instructions for installing them, see the following:

  • Click Samples on the Visual Studio Help menu.

    For more information, see Locating Sample Files.

  • The most recent versions and the complete list of samples are available on the Visual Studio 2008 Samples Web site.

  • You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied to a folder under \Program Files\Visual Studio 9\Samples\. For Visual Studio Express Editions, all samples are located on the Internet.

To run this sample

  • Press F5.

Demonstrates

This sample runs a time-consuming task on a separate thread, launched by a button click:

  • Run on same thread The task runs on the same thread as the main form. This blocks the user from interacting with the main form until the task finishes. No multithreading code is needed for this task.

  • Run on worker pool thread The task uses the BeginInvoke method created by the compiler for all delegates to run the task.

  • Background worker This task uses the BackgroundWorker Component to create a new thread.

This example does not include synchronization, because the multiple threads are not accessing any data.