Here's an example implementation of a thread pool in C# using the ThreadPool
class:
main.cs1681 chars69 lines
To use this thread pool, you would first create an instance of ThreadPoolExample
, passing in the number of worker threads you want in the thread pool. You can then add work items to the thread pool by calling the QueueWorkItem
method with an Action
representing the work to be done. Finally, you would start the thread pool by calling the Start
method, which creates the worker threads and starts the WorkLoop
method running in each thread.
gistlibby LogSnag