I have an external library that performs lengthy I / O operations. I want to create a multi-threaded application that will use ThreadPool to limit the number of threads at the same time, and I want to add threads that send these external calls as a termination thread thread (I / O threads), rather than worker threads (so there is a limitation on thread related threads) is not damaged.
I have a sample code that omits an external library, but shows that I have already tried.
Does anyone know how to do this? Or is it even possible. Thanks you
using System;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace ThreadPoolTest
{
class MainApp
{
static void Main()
{
ThreadPool.SetMaxThreads(10, 10);
ThreadPool.QueueUserWorkItem(DoWork);
ThreadPool.SetMaxThreads(10, 10);
((Action<object>)DoWork).BeginInvoke(null, Callback, null);
Console.Read();
}
static void DoWork(object o)
{
ShowAvailableThreads();
Thread.Sleep(10);
}
static void Callback(IAsyncResult ar)
{
ShowAvailableThreads();
}
static void ShowAvailableThreads()
{
int workerThreads, completionPortThreads;
ThreadPool.GetAvailableThreads(out workerThreads,
out completionPortThreads);
Console.WriteLine("WorkerThreads: {0}," +
" CompletionPortThreads: {1}",
workerThreads, completionPortThreads);
}
}
}