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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:33:10+00:00 2026-05-27T04:33:10+00:00

I have a database-synchronisation task that takes some time to process, as there are

  • 0

I have a database-synchronisation task that takes some time to process, as there are in the region of 120k leaf records, but they are remote and relatively slow to access.

Currently, my app does a fairly naive process of

  1. Get list of all the local Contacts
  2. For each local contact, get all the related data
  3. Then get the matching remote contact
  4. Compare the two and do stuff to bring them in sync

Step 1 returns data before it’s finished, and step 4 doesn’t involve comparisons between different contacts in the same set.

What I was hoping to do was use some sort of queue construct and start populating it in step 1, then immediately move onto step 2 and start processing items as they come in, using multiple threads.

The process then becomes:

  1. Start populating the queue with contacts
  2. While there are items in the queue
  3. Start a thread and:
    1. Take the front contact from the queue
    2. Fetch the remote contact
    3. Compare them
    4. Perform the required updates

Am I correct in the assumption that I can create a new ConcurrentQueue, start populating it, then loop over it as I might a single-threaded simple collection?

(I’ve not put in any error-checking or the actual threading, to keep the example simple)

class Program
{
    static void Main(string[] args)
    {
        Processor p = new Processor();
        p.Process();
    }
}


class Processor
{
    bool FetchComplete = false;
    ConcurrentQueue<Contact> q = new ConcurrentQueue<Contact>();

    public void Process()
    {
        this.PopulateQueue(); // this will be fired off using QueueUserWorkItem for example

        while (FetchComplete == false)
        {
            if (q.Count > 0)
            {
                Contact contact;
                q.TryDequeue(out contact);
                ProcessContact(contact); // this will also be in QueueUserWorkItem
            }
        }
    }


    // a long running process that fills the queue with Contacts
    private void PopulateQueue()
    {
        this.FetchComplete = false;
        // foreach contact in database
        Contact contact = new Contact(); // contact will come from DB
        this.q.Enqueue(contact);
        // end foreach

        this.FetchComplete = true;
    }

    private void ProcessContact(Contact contact)
    {
        // do magic with contact
    }
}
  • 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-05-27T04:33:10+00:00Added an answer on May 27, 2026 at 4:33 am

    You might be better off using BlockingCollection instead of ConcurrentQueue. The reason being that the former will block the thread calling Take until an item appears in the queue. This would be useful when the thread processing the Contract instances clears out the queue before the fetching thread has retrieved them all.

    In general your strategy is pretty solid. I use it all the time. It is often referred to as the producer-consumer pattern. When there are more than 2 stages involved in the processing then it is called the pipeline pattern. In that case you would have 2 or more queues instead of the typical one. You can imagine scenarios where each stage forwards the work item onto the next stage via another queue.

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

Sidebar

Related Questions

I have Database with date field. I see the time like: 1900-01-01 13:38:00.000 How
I have a database that contains a date and we are using the MaskedEditExtender
I have an application that connects to a database and can be used in
Is it possible to have some kind of type converter that allows Sync Framework
I'm developing an IPad application that use a prefeatched database with a synchronisation feature
There have been many questions along these lines but I'm struggling to apply them
I have database with many tables. In the first table, I have a field
I have database application, I want to allow the user to restore the deleted
i have database table like this +-------+--------------+----------+ | id | ip | date |
Currently I have database with the following associations: One Client to Many Intakes One

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.