DCTekSolutions.CycleKit 1.0.1

dotnet add package DCTekSolutions.CycleKit --version 1.0.1
                    
NuGet\Install-Package DCTekSolutions.CycleKit -Version 1.0.1
                    
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="DCTekSolutions.CycleKit" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DCTekSolutions.CycleKit" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="DCTekSolutions.CycleKit" />
                    
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 DCTekSolutions.CycleKit --version 1.0.1
                    
#r "nuget: DCTekSolutions.CycleKit, 1.0.1"
                    
#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 DCTekSolutions.CycleKit@1.0.1
                    
#: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=DCTekSolutions.CycleKit&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=DCTekSolutions.CycleKit&version=1.0.1
                    
Install as a Cake Tool

CycleKit

CycleKit provides a powerful, thread-safe queue that cycles endlessly through items.
Perfect for round-robin processing, rotating playlists, or any scenario where looping through a fixed set of items is needed.

Free to use for personal and commercial projects. This package is closed source.


Features

  • Thread-safe cycling queue (ConcurrentLoopingQueue<T>)
  • Supports both synchronous and asynchronous operations
  • Can be used with or without async/await
  • Optional Try pattern for non-throwing access
  • Supports resetting, peeking, and bounded iteration

🚀 Usage Examples

1. Sync Example – Load Balancing Across Servers

public class ServerNode
{
    public string Hostname { get; init; }
    public bool IsOnline { get; set; }

    public void HandleRequest(string request)
    {
        Console.WriteLine($"{Hostname} processing: {request}");
    }
}

// Setup the pool
var nodes = new List<ServerNode>
{
    new() { Hostname = "api-node-1", IsOnline = true },
    new() { Hostname = "api-node-2", IsOnline = true },
    new() { Hostname = "api-node-3", IsOnline = true }
};

var queue = new ConcurrentLoopingQueue<ServerNode>(nodes);

// Simulate incoming requests
for (int i = 0; i < 10; i++)
{
    if (queue.TryNext(out var server) && server.IsOnline)
    {
        server.HandleRequest($"Request #{i + 1}");
    }
}

2. Async Example – Distributed Worker Job Assignment

public class Worker
{
    public string Id { get; init; }

    public async Task ProcessJobAsync(string job)
    {
        Console.WriteLine($"[{Id}] started: {job}");
        await Task.Delay(250); // simulate work
        Console.WriteLine($"[{Id}] finished: {job}");
    }
}

var workers = new List<Worker>
{
    new() { Id = "Worker-A" },
    new() { Id = "Worker-B" },
    new() { Id = "Worker-C" }
};

var workerQueue = new ConcurrentLoopingQueue<Worker>(workers);

// Simulate async job dispatch
var jobTasks = new List<Task>();
for (int i = 0; i < 9; i++)
{
    string job = $"Job-{i + 1}";
    var worker = await workerQueue.NextAsync();
    jobTasks.Add(worker.ProcessJobAsync(job));
}

await Task.WhenAll(jobTasks);

3. TryGet / TryRemove / Reset Example

// Try to find a server by name
if (queue.TryGet(s => s.Hostname == "api-node-2", out var targetNode))
{
    Console.WriteLine($"Found: {targetNode.Hostname}");
}

// Remove an offline server
queue.TryRemove(targetNode);

// Reset queue to start at beginning
queue.TryReset();

🔄 Why CycleKit?

  • Predictable round-robin behavior
  • No memory reallocation from cycling
  • Built-in safety for multi-threaded environments
  • Async + Sync access without duplication
  • Ideal for routing, dispatching, retries, playback, and carousel logic

🧠 Pro Tip: Combine with SafeInvoker for Thread Safety

If you're using ConcurrentLoopingQueue<T> in a WPF UI context, pair it with DCTekSolutions.SafeInvoker:

public class MyViewModel : DispatcherObject
{
    private readonly IConcurrentLoopingQueue<JobItem> _jobQueue;

    public MyViewModel(IConcurrentLoopingQueue<JobItem> jobQueue)
    {
        _jobQueue = jobQueue;
    }

    [SafeInvokeWPF]
    public void ScheduleJob()
    {
        if (_jobQueue.TryNext(out var job))
        {
            // This safely runs on the UI thread
            ProcessJob(job);
        }
    }
}

Or use the SafeInvoke extension directly:

this.SafeInvoke(vm =>
{
    if (_jobQueue.TryNext(out var job))
        vm.Execute(job);
});

SafeInvoker ensures method calls that interact with DispatcherObject are executed safely on the UI thread—especially important when consuming CycleKit queues in ViewModels.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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. 
.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 was computed.  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.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.

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
1.0.1 133 6/22/2025
1.0.0 142 6/20/2025

Release 1.0.0
           - Initial release of ConcurrentLoopingQueue<T>
           - Thread-safe, round-robin queue with async support
           - Supports both synchronous and asynchronous access
           - .NET Standard 2.0 and 2.1 compatible
Release 1.0.1
- Added .ToList<T>()