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                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NuExt.System" Version="0.3.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NuExt.System --version 0.3.3                
#r "nuget: NuExt.System, 0.3.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 multiple IAsyncDisposable 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 of IDisposable.
  • System.Lifetime: Manages the lifecycle of objects and resources.
  • System.PropertyChangeNotifier: Implementation of INotifyPropertyChanged.
  • 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:

  1. Go to Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution....
  2. Search for NuExt.System.
  3. 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:

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last updated
0.3.3 145 2/21/2025
0.3.2 144 1/22/2025
0.3.1 131 1/19/2025
0.3.0 127 1/13/2025