You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ikopylov edited this page Mar 21, 2015
·
7 revisions
Qoollo QueueAsyncProcessor
One of the most common scenario in parallel data processing is to put the data to the thread-safe blocking queue and later take and process them in multiple threads. If you want to use this pattern then QueueAsyncProcessor is right what you need.
Sample source code:
// Define subclass of QueueAsyncProcessor parametrized with type of elementspublicclassDataProcessor:QueueAsyncProcessor<int>{publicDataProcessor(intthreadCount,intmaxQueueSize):base(threadCount:threadCount,maxQueueSize:maxQueueSize,name:"name"){}// Implement main process methodprotectedoverridevoidProcess(intelement,objectstate,CancellationTokentoken){Console.WriteLine(element);}}// usagestaticvoidMain(){// Create instance of QueueAsyncProcessorDataProcessorprocessor=newDataProcessor(Environment.ProcessorCount,64*Environment.ProcessorCount);// Start our processorprocessor.Start();// Add elements for processingfor(inti=0;i<100;i++)processor.Add(i);// Stop our processorprocessor.Stop(waitForStop:true,letFinishProcess:true,completeAdding:true);}
If you need, there's also exist a version of processor which received a processing delegate as constructor parameter (DelegateQueueAsyncProcessor).