K
Keith O
I know that you can queue thousands of jobs to the threadpool, but what if I
want to control how many jobs are queued. Here is an algorithm I came up
with. Please tell me if there is anything wrong with it, or if you have a
better way to handle this:
int c = 0;
while (DB.readRow())
{
if (c < MAX_QUEUE_SIZE)
{
c++;
ThreadPool.QueueUserWorkItem(new WaitCallback(DoThis));
}
else
{
lock.Wait();
}
}
....
....
....
public void DoThis()
{
...
...
...
c--;
lock.Pulse();
}
want to control how many jobs are queued. Here is an algorithm I came up
with. Please tell me if there is anything wrong with it, or if you have a
better way to handle this:
int c = 0;
while (DB.readRow())
{
if (c < MAX_QUEUE_SIZE)
{
c++;
ThreadPool.QueueUserWorkItem(new WaitCallback(DoThis));
}
else
{
lock.Wait();
}
}
....
....
....
public void DoThis()
{
...
...
...
c--;
lock.Pulse();
}