I have this Queue
declared in my class:
static private Queue<SignerDocument> QUEUE = new Queue<SignerDocument>();
I fill this Queue
with some items to process, and I want to process it using multithreading.
Did I need to use lock in this case, to ensure that QUEUE.Dequeue
is thread-safe?
static protected void ThreadProcManager()
{
lock (typeof(Queue<SignerDocument>))
{
if (QUEUE.Count > 0)
{
ThreadPool.QueueUserWorkItem(ThreadProc, QUEUE.Dequeue());
}
}
}
static private void ThreadProc(Object stateInfo)
{
//Do the work...
}