{"id":26155503,"url":"https://github.com/ntdls/ntdls.delegatethreadpooling","last_synced_at":"2025-04-14T07:42:35.757Z","repository":{"id":217683145,"uuid":"744600700","full_name":"NTDLS/NTDLS.DelegateThreadPooling","owner":"NTDLS","description":"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.","archived":false,"fork":false,"pushed_at":"2024-10-22T15:18:05.000Z","size":398,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-14T09:08:29.597Z","etag":null,"topics":["fifo","fifo-queue","high-performance","queue","threading","threadpool","threadpooling"],"latest_commit_sha":null,"homepage":"https://networkdls.com/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NTDLS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-17T16:24:00.000Z","updated_at":"2024-10-22T15:18:32.000Z","dependencies_parsed_at":"2024-10-22T23:02:35.978Z","dependency_job_id":"3fe9aa22-8a37-4506-95d6-a82447705a4a","html_url":"https://github.com/NTDLS/NTDLS.DelegateThreadPooling","commit_stats":null,"previous_names":["ntdls/ntdls.delegatethreadpool","ntdls/ntdls.delegatethreadpooling"],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NTDLS%2FNTDLS.DelegateThreadPooling","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NTDLS%2FNTDLS.DelegateThreadPooling/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NTDLS%2FNTDLS.DelegateThreadPooling/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NTDLS%2FNTDLS.DelegateThreadPooling/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NTDLS","download_url":"https://codeload.github.com/NTDLS/NTDLS.DelegateThreadPooling/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248842442,"owners_count":21170364,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fifo","fifo-queue","high-performance","queue","threading","threadpool","threadpooling"],"created_at":"2025-03-11T08:56:55.532Z","updated_at":"2025-04-14T07:42:35.726Z","avatar_url":"https://github.com/NTDLS.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NTDLS.DelegateThreadPooling\r\n\r\n📦 Be sure to check out the NuGet package: https://www.nuget.org/packages/NTDLS.DelegateThreadPooling\r\n\r\nHigh performance active thread pool where work items can be queued as delegate functions.\r\nAllows you to easily enqueue infinite FIFO worker items or enforce queue size, wait on collections\r\nof those items to complete, and total control over the pool size. Also allows for multiple pools,\r\nso that different workloads do not interfere with one another.\r\n\r\n_If you have ever been frustrated with **System.Threading.ThreadPool**, then this is likely the solution you are looking for._\r\n\r\n```cs\r\nprivate static readonly DelegateThreadPool _delegateThreadPool = new(10);\r\n\r\nstatic void Main()\r\n{\r\n    CollectionExample();\r\n    NoCollectionExample();\r\n\r\n    Console.WriteLine(\"Press [enter] to exit.\");\r\n    Console.ReadLine();\r\n\r\n    _delegateThreadPool.Dispose();\r\n}\r\n\r\nprivate static void CollectionExample()\r\n{\r\n    Console.WriteLine(\"CollectionExample: Starting to enqueue items...\");\r\n\r\n    var childPool = _delegateThreadPool.CreateChildPool();\r\n\r\n    //Enqueue work items as delegate functions.\r\n    for (int i = 0; i \u003c 100; i++)\r\n    {\r\n        childPool.Enqueue(() =\u003e\r\n        {\r\n            Thread.Sleep(1000); //Do some work...\r\n        });\r\n    }\r\n\r\n    Console.WriteLine(\"Enqueue complete, waiting on completion.\");\r\n\r\n    //Wait on all of the workitems to complete.\r\n    childPool.WaitForCompletion();\r\n\r\n    Console.WriteLine(\"All workers are complete.\");\r\n}\r\n\r\nprivate static void NoCollectionExample()\r\n{\r\n    Console.WriteLine(\"NoCollectionExample: Starting to enqueue items...\");\r\n\r\n    var itemStates = new List\u003cQueueItemState\u003cobject\u003e\u003e();\r\n\r\n    //Enqueue work items as delegate functions.\r\n    for (int i = 0; i \u003c 100; i++)\r\n    {\r\n        var queueItemState = _delegateThreadPool.Enqueue(() =\u003e\r\n        {\r\n            Thread.Sleep(1000); //Do some work...\r\n        });\r\n\r\n        itemStates.Add(queueItemState);\r\n    }\r\n\r\n    Console.WriteLine(\"Enqueue complete, waiting on completion.\");\r\n\r\n    //Wait on all of the workitems to complete.\r\n    itemStates.ForEach(t =\u003e t.WaitForCompletion());\r\n\r\n    Console.WriteLine(\"All workers are complete.\");\r\n}\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fntdls%2Fntdls.delegatethreadpooling","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fntdls%2Fntdls.delegatethreadpooling","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fntdls%2Fntdls.delegatethreadpooling/lists"}