Skip to content
ikopylov edited this page Dec 26, 2014 · 1 revision

Qoollo ThreadSetManager

It is often required to start one or several threads to execute some process asynchronously. It is very simple to create a System.Threading.Thread instance and start it, but it is always painful to implement the proper stop mechanism. ThreadSetManager can help you with that.

Sample code:

// Our action
private static void ThreadAction(CancellationToken token)
{
    while (!token.IsCancellationRequested)
    {
        // do some work
        Thread.Sleep(10);
    }
}

static void Main(string[] args)
{
    // Create thread manager
    var threadManager = new DelegateThreadSetManager(
                threadCount: 2,
                name: "name",
                tokenThreadStartAction: ThreadAction);

    // Start threads
    threadManager.Start();

    // Stop threads
    threadManager.Stop(waitForStop: true);
}