You want to remove the thread management code from your main thread and allow the task objects to manage their threads transparently.
Create a thread wrapper class that stores a reference to the thread and encapsulates the task-specific logic.
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 ...