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 8150107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:59:07+00:00 2026-06-06T14:59:07+00:00

I have the following async queue processing routing. var commandQueue = new BlockingCollection<MyCommand>(); commandQueue

  • 0

I have the following async queue processing routing.

      var commandQueue = new BlockingCollection<MyCommand>();
      commandQueue
            .GetConsumingEnumerable()
            .ToObservable(new LimitedConcurrencyLevelTaskPoolScheduler(5))
            .Subscribe(c =>
                           {
                               try
                               {
                                   ProcessCommand(c);
                               }
                               catch (Exception ex)
                               {
                                   Trace.TraceError(ex.ToString());
                               }
                           }
            );

In one specific scenario (when I’m about to get some data), I need to make sure that my commandQueue is empty before going out and getting the data. This operation is expected to happen synchronously. Basically, I want to do something like

  public void GetData()
  {
     commandQueue.WaitForEmpty(); 

     // could potentially be expressed: 
     // while (commandQueue.Count > 0) Thread.Sleep(10);

     return GoGetTheData()
  }

I realize that in an ideal scenario, all callers will “GetData” async…but sometimes it’s necessary that it happen in a synchronous manner…and so I need to wait for the command queue to be empty to ensure the consistency and up-to-date-ness of my data.

I know how I can do this pretty easily with a ManualResetEvent…but I’d like to know if there’s an easy way with System.Reactive/TPL.

Thanks.

  • 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-06T14:59:08+00:00Added an answer on June 6, 2026 at 2:59 pm

    This is a more difficult question than it seems at first. You want BlockingCollection (and the underlying ConcurrentQueue) for producer-consumer job semantics. But you also want to be able to observe what’s happening with these collections, including waiting for the ’empty’ signal.

    Best bet is to take a look at JobQueue and ParallelJobQueue from here:

    http://social.msdn.microsoft.com/Forums/en-US/rx/thread/2817c6e5-e5a4-4aac-91c1-97ba7de88ff7

    Which includes an observable for WhenQueueEmpty and can control the number of simultaneously running jobs and queued jobs (jobs being synonymous in this case with your command concept).

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

Sidebar

Related Questions

I have the following code in actionscript 3: var async:AsyncToken; async = bridge.retornamenu(); The
I have the following code in action script 3: async.addResponder(new Responder(result, defaultFaultHandler)); result is
I have the following method which uses implicit scheduling: private async Task FooAsync() {
i have following code ThreadPool.QueueUserWorkItem(new WaitCallback(DownloadAsync), apiMethod); downloadHandle.WaitOne(); Where DownloadAsync is private void DownloadAsync(object
I have the following ajax request: jQuery.ajax({ async: true, type: GET, url: url, data:
I have the following code: $('#DoButton').click(function (event) { event.preventDefault(); $(input:checked).each(function () { var id
I have the following javascript snippet: $.ajax({ url: self.LoadCirculationListUrl, cache: false, async: false, dataType:
Is there a simple way to do async in Perl? I have the following
I have following ajax call in my JavaScript code url = 'http://news.ycombinator.com/?callback=?'; $.ajax({url:url ,async:!1,dataType:'script',
I have the following extremely basic $.ajax function: function doAjax(url, args){ var retVal =

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.