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

  • Home
  • SEARCH
  • 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 7776025
In Process

The Archive Base Latest Questions

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

Basically I have a static custom queue of objects I want to process. From

  • 0

Basically I have a static custom queue of objects I want to process. From multiple threads, I need to kick off a singular Task that will process the queued objects, stopping the task when all items are dequeued.

Some psuedo code:

static CustomQueue _customqueue;
static Task _processQueuedItems;

public static void EnqueueSomething(object something) {
    _customqueue.Enqueue(something);
    StartProcessingQueue();
}

static void StartProcessingQueue() {
   if(_processQueuedItems != null) {
      _processQueuedItems = new Task(() => {
        while(_customqueue.Any()) {
            var stuffToDequeue = _customqueue.Dequeue();
            /* do stuff */
        }
      });
     _processQueuedItems.Start();
   }
   if(_processQueuedItems.Status != TaskStatus.Running) {
      _processQueuedItems.Start();
   }
}

If it makes a difference my custom queue is a queue that essentially holds items until they reach a certain age, then allows them to dequeue. Everytime an item is touched its timer starts again. I know this piece works fine.

The part I’m struggling with is the parallelism. (Clearly, I don’t know what I’m doing here). What I want is to have one thread process the queue until it’s complete, then go away. If another call comes in it doesn’t start a new thread unless it has to.

I hope that explains my issue okay.

  • 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-01T17:46:21+00:00Added an answer on June 1, 2026 at 5:46 pm

    You might want to consider using BlockingCollection<T> here. You could make your custom queue implement IProducerConsumerCollection, in which case BC could use it directly.

    You’d then just need to start a long running Task to call blockingCollection.GetConsumingEnumerable() and process the items in a foreach. The task will automatically block when the collection is empty, and restart when a new item is Enqueued.

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

Sidebar

Related Questions

So I basically want to have a static method in my AR class to
I'm getting confused by pointers in objective-c. Basically I have a bunch of static
I basically have a unix process running and it is doing some heavy processing
I basically have 7 select statements that I need to have the results output
I have a Service that downloads a file from the internet. What I want
I am learning JQuery. I have a need to create a custom control. This
When I run my code it doesn't show up. Basically I have a custom
Having some trouble passing values from one class to another. I basically have a
I have a custom class that is basically a SortedList with a few extra
I've created a custom adapter for my spinner because I wanted to have multiple

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.