Looking for something specific?
  Home
Home
Articles
Page Tag-Cloud
  Software
Software Tag-Cloud
Building from Source
Open Source Definition
All Software
  Popular Tags
Legacy
C Plus Plus
Source Code
Class
Cryptography
  Members
Login
Web-Email
Notable Members
  Official
Our Company
Copyright Information
Software EULA
GPL EULA
LGPL Eula
Pre-Release EULA
Privacy Policy
  Support
Make Contact
 
NTDLS.DelegateThreadPooling
Downloads   0
User Rating   (Rate)
Last Updated   3/12/2024
License   MIT License
- Download -
View all Releases
Recommended Release
Version   1.2.13
Date   3/12/2024
Status   Stable Stable software is believed to be stable and ready for production use.

This software is open source. You can obtain the latest source code from the GitHub repository or browse the releases for the source code associated with a specific release. If you make any changes which you feel improves this application, please let us know via our Contact Page.

NTDLS.DelegateThreadPooling

?? Be sure to check out the NuGet package: https://www.nuget.org/packages/NTDLS.DelegateThreadPooling

High performance active thread pool where work items can be queued as delegate functions. Allows you to easily enqueue infinite FIFO worker items or enforce queue size, wait on collections of those items to complete, and total control over the pool size. Also allows for multiple pools, so that different workloads do not interfere with one another.

If you have ever been frustrated with System.Threading.ThreadPool, then this is likely the solution you are looking for.

private static readonly DelegateThreadPool _delegateThreadPool = new(10);

static void Main()
{
    CollectionExample();
    NoCollectionExample();

    Console.WriteLine("Press [enter] to exit.");
    Console.ReadLine();

    _delegateThreadPool.Dispose();
}

private static void CollectionExample()
{
    Console.WriteLine("CollectionExample: Starting to enqueue items...");

    var childPool = _delegateThreadPool.CreateChildPool();

    //Enqueue work items as delegate functions.
    for (int i = 0; i < 100; i++)
    {
        childPool.Enqueue(() =>
        {
            Thread.Sleep(1000); //Do some work...
        });
    }

    Console.WriteLine("Enqueue complete, waiting on completion.");

    //Wait on all of the workitems to complete.
    childPool.WaitForCompletion();

    Console.WriteLine("All workers are complete.");
}

private static void NoCollectionExample()
{
    Console.WriteLine("NoCollectionExample: Starting to enqueue items...");

    var itemStates = new List<QueueItemState<object>>();

    //Enqueue work items as delegate functions.
    for (int i = 0; i < 100; i++)
    {
        var queueItemState = _delegateThreadPool.Enqueue(() =>
        {
            Thread.Sleep(1000); //Do some work...
        });

        itemStates.Add(queueItemState);
    }

    Console.WriteLine("Enqueue complete, waiting on completion.");

    //Wait on all of the workitems to complete.
    itemStates.ForEach(t => t.WaitForCompletion());

    Console.WriteLine("All workers are complete.");
}

Recent Releases:
 1.2.13    1.2.12    1.2.9    1.2.8    1.2.5    1.2.4    1.2.2    1.2.1    1.0.1    1.0.0  

Tags:
 Fifo    Fifo Queue    High Performance    Queue    Threading    Threadpool    Threadpooling  

No comments currently exists for this software. Why don't you add one?
First Previous Next Last 

 
Copyright © 2024 NetworkDLS.
All rights reserved.
 
Privacy Policy | Our Company | Contact