Skip to content

ConsumerAsyncWorkGroup

Brian Lehnen edited this page Apr 8, 2026 · 4 revisions

Consumer Workgroups

The async queue allows you limit the threads used in the task scheduler. This is done by creating a workgroup on the scheduler, and then passing that workgroup to the queue when you create it.

Note this does not reserve threads; it prevents a queue from using more than X number of threads in the scheduler. For instance, you may have very long running tasks. You might want those tasks to only execute one at a time to free up resources for shorter running tasks.

  • Creating workgroup
var group = taskScheduler.AddWorkGroup("workGroupName", 1);

The above example creates a work group with a max concurrency level of 1. This prevents any single queue from consuming more than 1 thread in the scheduler.

  • Assigning workgroup to a queue

To assign the workgroup to the queue, pass it in when creating the queue.

var queue = queueContainer.CreateConsumerQueueScheduler(queueConnection, taskFactory, group);

This queue will only be able to use a max of one thread in the scheduler. Work groups can be used with ConsumerMethodAsync and other scheduler-based consumers.

Clone this wiki locally