NuExt.System
0.3.3
Prefix Reserved
dotnet add package NuExt.System --version 0.3.3
NuGet\Install-Package NuExt.System -Version 0.3.3
<PackageReference Include="NuExt.System" Version="0.3.3" />
paket add NuExt.System --version 0.3.3
#r "nuget: NuExt.System, 0.3.3"
// Install NuExt.System as a Cake Addin #addin nuget:?package=NuExt.System&version=0.3.3 // Install NuExt.System as a Cake Tool #tool nuget:?package=NuExt.System&version=0.3.3
NuExt.System
NuExt.System
provides various fundamental extensions and classes for .NET, simplifying tasks related to asynchronous programming, resource lifecycle management, thread synchronization, and more.
Features
- Thread synchronization tools.
- Lifecycle management of objects and resources.
- Property change notifications implementation.
- Simplified asynchronous resource disposal.
- High-performance string manipulation utilities.
Commonly Used Types
System.AggregateDisposable
: Simplifies the disposal of multiple disposables.System.AggregateAsyncDisposable
: The asynchronous disposal of multipleIAsyncDisposable
instances.System.AsyncDisposable
: Facilitates async resource disposal.System.AsyncEventHandler
: Represents an asynchronous event handler.System.AsyncLifetime
: Manages the lifecycle of asynchronous operations.System.Disposable
: Base implementation ofIDisposable
.System.Lifetime
: Manages the lifecycle of objects and resources.System.PropertyChangeNotifier
: Implementation ofINotifyPropertyChanged
.System.Diagnostics.ProcessMonitor
: Real-time monitoring of CPU, memory and ThreadPool threads.System.Threading.AsyncLock
: Asynchronous lock for resource synchronization.System.Threading.AsyncWaitHandle
: Async wait handle with timeout and cancellation support.System.Threading.ReentrantAsyncLock
: Reentrant asynchronous lock.System.Text.ValueStringBuilder
: High-performance string builder (originally internal in .NET runtime).System.IO.PathBuilder
: Builder for constructing paths.System.IO.ValuePathBuilder
: High-performance builder for constructing paths.
Installation
You can install NuExt.System
via NuGet:
dotnet add package NuExt.System
Or via the Visual Studio package manager:
- Go to
Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution...
. - Search for
NuExt.System
. - Click "Install".
ReentrantAsyncLock Internals
The ReentrantAsyncLock
class provides a reentrant (re-enterable) asynchronous lock. This means that the same thread can acquire the lock multiple times without blocking itself. It is particularly useful for complex asynchronous scenarios where recursive calls are expected.
ReentrantAsyncLock
relies on AsyncLocal
to manage the lock's state across asynchronous method calls, ensuring that the lock is associated with the correct execution context. AsyncLocal
variables store data that is unique to a particular asynchronous control flow, allowing different asynchronous operations to have their own distinct contexts.
In most cases, you won't encounter any issues. However, in specific scenarios where certain methods, such as CancellationToken.Register
, might capture the ExecutionContext
, here's an example demonstrating a preferred usage. Instead of:
var asyncLock = new ReentrantAsyncLock();
var cts = new CancellationTokenSource();
asyncLock.Acquire(() => cts.Token.Register(() => asyncLock.Acquire(() =>
{
// user code
})));
asyncLock.Acquire(() => cts.Cancel());
It is preferable to do:
var asyncLock = new ReentrantAsyncLock();
var cts = new CancellationTokenSource();
asyncLock.Acquire(() =>
{
//Don't capture the current ExecutionContext and its AsyncLocals for CancellationToken.Register
using (ExecutionContext.SuppressFlow())
{
cts.Token.Register(() => asyncLock.Acquire(() =>
{
// user code
}));
}
//The current ExecutionContext is restored after exiting the using block
});
asyncLock.Acquire(() => cts.Cancel());
This ensures that the AsyncLocal
values do not unintentionally flow into the registered callbacks, maintaining the intended behavior of your application.
Usage Examples
For comprehensive examples of how to use the package, see samples in the following repositories:
- NuExt.System.Data.SQLite
- NuExt.DevExpress.Mvvm
- NuExt.DevExpress.Mvvm.MahApps.Metro
- NuExt.Minimal.Mvvm.Windows
- NuExt.Minimal.Mvvm.MahApps.Metro
Acknowledgements
Includes code derived from the .NET Runtime, licensed under the MIT License. The original source code can be found in the .NET Runtime GitHub repository.
License
Licensed under the MIT License. See the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- Microsoft.Bcl.HashCode (>= 6.0.0)
- System.Text.Json (>= 9.0.2)
-
.NETStandard 2.0
- Microsoft.Bcl.HashCode (>= 6.0.0)
- System.Text.Json (>= 9.0.2)
-
.NETStandard 2.1
- System.Text.Json (>= 9.0.2)
-
net6.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on NuExt.System:
Package | Downloads |
---|---|
NuExt.System.Windows
Provides essential extensions and utilities for Windows application development with a focus on WPF. Commonly Used Types: System.Diagnostics.BindingErrorTraceListener System.IO.IOUtils System.Windows.BindingProxy System.Windows.BindingProxy<T> System.Windows.WindowPlacement System.Windows.IDragDrop |
|
NuExt.System.Data
Provides various extensions for data classes. Commonly Used Types: System.Data.DalBase System.Data.DataReaderExtensions System.Data.DataRowExtensions System.Data.DataTableExtensions System.Data.DalBase System.Data.DbConverter<TDbConnection> System.Data.IDbContext |
GitHub repositories
This package is not used by any popular GitHub repositories.