Skip to main content
net10.0net11.0

Types and extension methods to help with threading

Published
Nov 8, 2026
10d ago
Total Downloads
91.0K
91,040

Install

dotnet add package Meziantou.Framework.Threading --version 3.1.9
ProductVersions
.NET
net10.0net11.0

README

Meziantou.Framework.Threading

Provides types such as

  • ConcurrentHashSet<T>
  • ConcurrentObservableCollection<T>
  • SynchronizedList<T>
  • AsyncAutoResetEvent
  • AsyncLock
  • ResettableCancellationTokenSource
  • KeyedLock
  • KeyedAsyncLock

Provides extensions methods for

  • SemaphoreSlim
  • Task

Simplifying task awaiting (blog post). The extension methods are in the Meziantou.Framework.Threading.Tasks namespace.

var task1 = Task.FromResult(42);
var task2 = Task.FromResult("value");

var (a, b) = await (task1, task2);
Assert.Equal(42, a);
Assert.Equal("value", b);

var (c, d) = await (task1, task2).ConfigureAwait(false);
Assert.Equal(42, c);
Assert.Equal("value", d);

Thread-safe collection that can be bound to a UI control (ConcurrentObservableCollection<T> is in the Meziantou.Framework.Collections.Concurrent namespace)

// Created on the UI thread, so the notifications are raised on that thread
var collection = new ConcurrentObservableCollection<string>();
listBox.ItemsSource = collection.AsObservable;

// The collection itself is safe to use from any thread
await Task.Run(() => collection.Add("Item from a background thread"));

The thread the notifications are raised on can also be set explicitly with a SynchronizationContext:

var collection = new ConcurrentObservableCollection<string>(synchronizationContext);

Changes from Previous Version

No structural changes between v3.1.8 and v3.1.9.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

Compatibility metadata lists 2 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.