public override void processItem(Bitmap bitmap) { if (outQueue.Count != 0) { Thread.Sleep(1); return; } var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); var filteredBitmaps = new KeyValuePair <KeyValuePair <Bitmap, BitmapData>, TargetDescriptor> [settings.TargetDescriptors.Count]; var lockobj = new object(); var i = 0; Parallel.ForEach(settings.TargetDescriptors, targetDescriptor => { var result = new KeyValuePair <KeyValuePair <Bitmap, BitmapData>, TargetDescriptor>(ColorFilter.FilterImage(ref bitmapData, targetDescriptor.filter, targetDescriptor.priority), targetDescriptor); lock (lockobj) filteredBitmaps[i++] = result; }); StaticInstance.STP.QueueWorkItem((b, bd) => { b.UnlockBits(bd); b.Dispose(); }, bitmap, bitmapData); outQueue.Enqueue(filteredBitmaps); }