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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:36:32+00:00 2026-06-10T09:36:32+00:00

I understand the concepts around multithreading and using Thread Pools. One concept I am

  • 0

I understand the concepts around multithreading and using Thread Pools. One concept I am trying to figure out is how to keep track of what emails have been sent to on each thread. So imagine, each thread is responsible for pulling x number of records, iterating through those emails, applying an email template, then saving the email to a pick up directory. Obviously, I need a way to tell each thread not to pull the same data as another thread.

One solution I was thinking was to page the data, have a global variable or array to keep track of the pages already sent to, have each thread examine that variable and start from the next available page. The only issue I can think of is if the data changes, then the pages available might get out of sync.

another solution is to set a boolean value in the database to determine if an account has been emailed to or not. So, EF would pull X amount of records and update those records as being ready to email on. This way each query would only look for emails that are not ready to be emailed to.

I wanted to get some other suggestions, if possible, or expand on the solutions I provided.

  • 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-10T09:36:33+00:00Added an answer on June 10, 2026 at 9:36 am

    Given that you may one day want to scale to more than one app server, memory synchronization implementations might also not be sufficient to guarantee that emails are not duplicated.

    One of the simplest ways to solve is to implement a batch processing mechanism would be at the database level.

    Under a Unit of Work

    • Read N x records, with Pessimistic Locking (i.e. preventing concurrent reads by other threads pulling the same emails)
    • Stamp these records with a batch id (or a IsProcessed Indicator)
    • Return the records to your app

    e.g. a Batching PROC in SQL server might look something like (Assuming table = dbo.Emails, which has a PK EmailId and a processed indicator BIT field IsProcessed):

    CREATE PROC dbo.GetNextBatchOfEmails
    AS
        BEGIN
            -- Identify the next N emails to be batched. UPDLOCK is to prevent another thread batching same emails
            SELECT top 100 EmailId 
            INTO #tmpBatch
                FROM dbo.Emails WITH (UPDLOCK)
                WHERE IsProcessed = 0
    
            -- Stamp emails as sent. Assumed that PROC is called under a UOW. The batch IS the UOW
            UPDATE e
                SET e.IsProcessed = 1
                FROM dbo.Emails e
                INNER JOIN #tmpBatch t
                    on e.EmailId = t.EmailId
    
            -- Return the batch of emails to caller
            SELECT e.*
                FROM dbo.Emails e
                INNER JOIN #tmpBatch t
                    on e.EmailId = t.EmailId
        END
    

    Then expose the PROC as an EF Function Import mapped to your Email Entity. Under a TransactionScope ts, you can then call the EF Function Import, and send emails, and call ts.Complete() on success.

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

Sidebar

Related Questions

I am trying to better understand basic concepts in OOP. What are static and
I'm trying to understand the main concepts of graph theory and the algorithms within
I think one of the more difficult concepts to understand in the Zend Framework
I understand the concept and reasons behind using the using statement, and I use
I am trying to understand the concept of currying and calling a function which
I am trying to understand the concept of timestamps in request headers in web
I'm trying to better understand the concept of 'autocommit' when working with a Postgres
I'm trying to wrap my head around the basic concepts of the R programming
I'm trying to figure out my first more complex SQL application and am having
I understand the concepts behind refs/heads/ , refs/remotes/ , and refs/tags/ . From time

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.