SimpliSharp 0.2.2

dotnet add package SimpliSharp --version 0.2.2
                    
NuGet\Install-Package SimpliSharp -Version 0.2.2
                    
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="SimpliSharp" Version="0.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SimpliSharp" Version="0.2.2" />
                    
Directory.Packages.props
<PackageReference Include="SimpliSharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SimpliSharp --version 0.2.2
                    
#r "nuget: SimpliSharp, 0.2.2"
                    
#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.
#:package SimpliSharp@0.2.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SimpliSharp&version=0.2.2
                    
Install as a Cake Addin
#tool nuget:?package=SimpliSharp&version=0.2.2
                    
Install as a Cake Tool

SimpliSharp

A utility library designed to streamline development with useful extensions, helpers, data processing tools, and logging helpers.

.NETGitHub last commit GitHub stars

SmartDataProcessor

The SmartDataProcessor<T> is designed to process a queue of items in parallel, while automatically adjusting the level of concurrency to stay within a specified CPU usage limit.

Features

  • Dynamic Concurrency: Automatically adjusts the number of worker threads based on real-time CPU load.
  • CPU Throttling: Ensures that CPU usage does not exceed a configurable maximum limit.
  • Backpressure: The EnqueueOrWait method blocks when the queue is full or the CPU is saturated, preventing memory overload.
  • Lazy Initialization: The processing thread pool is only created when the first item is enqueued.
  • Configurable: Fine-tune performance with the SmartDataProcessorSettings class.
  • Event-driven: Subscribe to events for CPU usage changes and exceptions.
  • Runtime Control: Pause and resume the processor on the fly.

Usage Example

You can now configure the processor using the SmartDataProcessorSettings class:

var settings = new SmartDataProcessorSettings
{
    MaxCpuUsage = 80, // Target 80% CPU usage
    MaxDegreeOfParallelism = 4, // Use a maximum of 4 threads
    QueueBufferMultiplier = 8 // Set a larger queue buffer
};

using var processor = new SmartDataProcessor<int>(settings);

// Subscribe to events
processor.OnCpuUsageChange += (cpuLoad) => Console.WriteLine($"CPU Load: {cpuLoad:F1}%");
processor.OnException += (ex) => Console.WriteLine($"An error occurred: {ex.Message}");

// Enqueue items
for (int i = 0; i < 100; i++)
{
    processor.EnqueueOrWaitAsync(i, data =>
    {
        // Your processing logic here...
    });
}

// Pause and resume processing
processor.Pause();
Thread.Sleep(5000);
processor.Resume();

processor.WaitForAllAsync().Wait();

Alt text for your image

Enumerable Extensions

Batching

Batching enumerables using Enumerables.Batch(batchSize) or Enumerables.BatchSliding(windowSize) will simply yield the requested batches,

string[] sample = ["Red", "Blue", "Purple", "Black", "Yellow", "Pink"];
string[][] batches = sample.Batch(3).ToArray();

// Batch 1: [Red, Blue, Purple]
// Batch 2: [Black, Yellow, Pink]
int[] sample = [1, 2, 3];
int[][] batches = sample.BatchSliding(2).ToArray();

// Batch 1: [1, 2]
// Batch 2: [2, 3]
Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.2 204 9/7/2025
0.2.1 201 9/4/2025
0.1.0 231 8/30/2025