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 Reusable Task Processor

Problem

You need a dedicated thread that will process queue tasks and process them continuously.

Solution

Create a threaded class that stores tasks in a queue and monitors the queue continuously.

Discussion

A common pattern in distributed application design is a task processor: a dedicated thread that performs requested tasks on a first-in-first-out basis. This thread lives for the life of the application and uses an internal collection (typically a queue) to store requested tasks until it has a chance to process them.

Creating a task processor is fairly easy. However, to do it properly, you need to leverage the stop request pattern and thread wrapper pattern shown in recipes Stop a Thread Politely and Create a Thread ...

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