Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7768275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:52:46+00:00 2026-06-01T15:52:46+00:00

I need single-producer, single-consumer FIFO query because I need to process messages in the

  • 0

I need single-producer, single-consumer FIFO query because

  • I need to process messages in the order they received.
  • I need to do this asynchronous because caller should not wait while I’m processing message.
  • Next message processing should be started only when previous message processing is finished. Sometimes frequency of “receiving” messages is higher than frequency of “processing” messages. But in average I should be able to process all messages, just sometimes I have to “queue” pack of them.

So it’s pretty like TCP/IP I think, where you have one producer and one consumer, SOMETIMES you can receive messages faster than you can process, so you have to query them. Where order IS important and where caller absolutely not interested what you doing with that stuff.

This sounds easy enough and I likely can use general Queue for that, but I want to use BlockingCollection for that because I don’t want to write any code with ManualResetEvent etc.

How suitable BlockingCollection for my task and probably you can suggest something else?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:52:48+00:00Added an answer on June 1, 2026 at 3:52 pm

    BlockingCollection class implements IProducerConsumerCollection interface so perfectly fits your requirements.

    You can create two Tasks, one for async producer and an other one as consumer worker. Former would add items to BlockingCollection and the latter just consume as soon as new are available in FIFO order.

    Producer-consumer sample application using TPL Tasks and BlockingCollection:

    class ProducerConsumer
    {
        private static BlockingCollection<string> queue = new BlockingCollection<string>();
    
        static void Main(string[] args)
        {
            Start();
        }
    
        public static void Start()
        {
            var producerWorker = Task.Factory.StartNew(() => RunProducer());
            var consumerWorker = Task.Factory.StartNew(() => RunConsumer());
    
            Task.WaitAll(producerWorker, consumerWorker);
        }
    
        private static void RunProducer()
        {
            int itemsCount = 100;
    
            while (itemsCount-- > 0)
            {
                queue.Add(itemsCount + " - " + Guid.NewGuid().ToString());
                Thread.Sleep(250);
            }
        }
    
        private static void RunConsumer()
        {
            foreach (var item in queue.GetConsumingEnumerable())
            {
               Console.WriteLine(DateTime.Now.ToString("HH:mm:ss.ffff") + " | " + item);
            }
        }
    }
    

    IProducerConsumerCollection:

    Defines methods to manipulate thread-safe collections intended for
    producer/consumer usage. This interface provides a unified
    representation for producer/consumer collections so that higher level
    abstractions such as
    System.Collections.Concurrent.BlockingCollection(Of T) can use the
    collection as the underlying storage mechanism.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to implement a producer/consumer bounded queue, multiple consumers against a single producer.
I need to Justify single line text and I had this issue in past
How can I snapshot backup/restore JCR repository? I need complete integrity. This means, single
Briefly under a single producer - single consumer scenario, I used a mutable object
i need single file wsdl, how to build single file wsdl? Thanks.
Need suggestions on implementing associating single or many objects to an entity. All soccer
I need to create a single trace file that spans several days for one
I need to display a single list, ordered by date which contains different types
I need to develop a single routine that will be fired each 5 minutes
I need to map a single fixed sized array array to multiple properties. For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.