Install
dotnet add package Meziantou.Framework.Threading --version 3.1.8
| Product | Versions |
|---|---|
| .NET |
README
Meziantou.Framework.Threading
Provides types such as
ConcurrentHashSet<T>ConcurrentObservableCollection<T>SynchronizedList<T>AsyncAutoResetEventAsyncLockResettableCancellationTokenSourceKeyedLockKeyedAsyncLock
Provides extensions methods for
SemaphoreSlimTask
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.7 and v3.1.8.
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.