private static void RemoveBackground(BlockingCollection <BitmapWithFilePathAndSeq> inputQueue, Bitmap background_bm, CancellationTokenSource cts, CancellationToken suspensionToken, params BlockingCollection <BitmapWithFilePathAndSeq>[] outputQueues)
        {
            CancellationToken token = cts.Token;

            try
            {
                foreach (var input in inputQueue.GetConsumingEnumerable())
                {
                    if (token.IsCancellationRequested)
                    {
                        break;
                    }

                    lock (input.Image)
                    {
                        lock (background_bm)
                        {
                            var result = ImageProcessor.RemoveBackground(input.Image, background_bm);

                            for (int i = 0; i < outputQueues.Length; i++)
                            {
                                if (token.IsCancellationRequested)
                                {
                                    break;
                                }

                                outputQueues[i].Add(new BitmapWithFilePathAndSeq()
                                {
                                    FilePath = input.FilePath,
                                    Image    = (Bitmap)result.Clone(),
                                    SeqId    = input.SeqId,
                                }, token);
                            }
                        }
                    }

                    if (suspensionToken.IsCancellationRequested)
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                if (!(ex is OperationCanceledException))
                {
                    cts.Cancel();
                    throw;
                }
            }
            finally
            {
                foreach (var outputQueue in outputQueues)
                {
                    outputQueue.CompleteAdding();
                }
            }
        }
        /// <summary>
        /// Executes a image processing operation.
        /// </summary>
        /// <param name="filePath">Path to the file image to process.</param>
        /// <param name="background_bm">The background image.</param>
        private static void ExecuteSequentialOperation(string filePath, Bitmap background_bm)
        {
            Bitmap target_bm = ImageProcessor.LoadFileAsImage(filePath);

            target_bm = ImageProcessor.RemoveBackground(target_bm, background_bm);
            Bitmap target_thumb_bm = ImageProcessor.ResizeToThumbnail(target_bm);

            string output       = OutputDirectory + Path.DirectorySeparatorChar + Path.GetFileName(filePath);
            string output_thumb = OutputDirectory + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(filePath) + "_thumbnail" + Path.GetExtension(filePath);

            ImageProcessor.SaveBitmapToFile(target_bm, output);
            ImageProcessor.SaveBitmapToFile(target_thumb_bm, output_thumb);
        }