A thread-safe asynchronous producer-consumer model.

View the Project on GitHub



Scheduler is an asynchronous producer-consumer model that allows producers concurrently add items to the collection and consumes each item from the collection in single thread.


The flow can be summarized with following steps:

  1. A producer adds an item to the collection by calling AddAndRun or TryAddAndRun method.
  2. Scheduler checks whether the item is the first one in the collection. If so, the main loop thread will be launched.
  3. Action consumes the item from the collection.
  4. Scheduler checks whether the collection is empty. If so, main loop thread ends. If not, repeats step 3.

The Scheduler performs following behaviors to handle main loop thread:

Redis Integration

This project defines a set of Redis wrapper that can be used to replace in-memory collection. In this scenario, items are stored in Redis list instead of local memory and wrapped by RedisQueue or RedisStack. This can avoid large local memory use when a number of items are not consumed yet.

Overview Redis

By applying ObservableRedisQueue or ObservableRedisStack, which implements INotifyCollectionChanged interface, it is also possible that multiple application instances share same collection. Once new items have been added via an application instance, all instances sharing same Redis collection will receive the notification and start the main loop thread respectively.

Overview Observable Redis

The Redis wrappers are defined in ModelWorkshop.Scheduling.Redis namespace.


This project targets .Net Core and .Net Framework 4.5.