O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

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

Create a Thread Wrapper Class

Problem

You want to remove the thread management code from your main thread and allow the task objects to manage their threads transparently.

Solution

Create a thread wrapper class that stores a reference to the thread and encapsulates the task-specific logic.

Discussion

One common design pattern with multithreading is to create a thread wrapper. This wrapper provides the typical methods you would expect in a Thread, like Start and Stop, along with all the task-specific code, and provides properties for required input values and calculated values.

Here’s an abstract base class that defines the basic structure of a well-behaved thread wrapper:

Public MustInherit Class ThreadWrapperBase ' This is the thread where the task ...

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