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

The Archive Base Latest Questions

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

All i am using a quartz schedular for scheduling a job in an asp.net

  • 0

All i am using a quartz schedular for scheduling a job in an asp.net mvc application.This schedular schedules a job after fixed interval of time.

http://quartznet.sourceforge.net/

The service i have created basically runs every minute.It reads the message from the
message que(database in my case) every 1min , sends an email and updates the message sent status
to true.
I am having some problems though.TO be specific the problem is the service sends the same email twice because of the reasons mentioned below.

In some cases the service gets called as soon as an email is send before the db update happens.As The database update does not happen after sending email and service is invoked again,the processed message is again read from the database as unread message and gets resent.

The same message is read again from database.Thus the service ends of sending same message twice.

How do i handle this case in my code.

public void Execute(JobExecutionContext context)
        {
            List<QueuedEmail> lstQueuedEmail =
                _svcQueuedEmail.Filter((x => x.IsSent == false)).Take(NO_OF_MAILS_TO_SEND).ToList();
            if (lstQueuedEmail.Count > 0)
            {
                foreach (var queuedEmail in lstQueuedEmail)
                {
                    try
                    {
                        bool emailSendStatus = false;

                        emailSendStatus = EmailHelper.SendEmail(queuedEmail.From, queuedEmail.To, queuedEmail.Subject,
                                                                queuedEmail.Body, queuedEmail.FromName);
                        QueuedEmail objQueuedEmail =
                            _svcQueuedEmail.Filter(x => x.Id == queuedEmail.Id).FirstOrDefault();
                        if (emailSendStatus)
                        {
                            objQueuedEmail.IsSent = true;
                            objQueuedEmail.SentOnUtc = DateTime.UtcNow;
                        }
                        else
                        {
                            objQueuedEmail.IsSent = false;
                            if (objQueuedEmail.SentTries == null)
                            {
                                objQueuedEmail.SentTries = 1;
                            }
                            else
                            {
                                objQueuedEmail.SentTries += 1;
                            }
                        }
                        _svcQueuedEmail.Update(objQueuedEmail);
                    }
                    catch (Exception)
                    {
                        //log error 
                    }
                }
            }
        }
  • 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:06:34+00:00Added an answer on June 10, 2026 at 9:06 am

    Assuming you have two states for an email: “Pending” and “Sent”.

    You should add a third an intermediary state called “Sending” and as soon as you read the email from the Queue you should change it’s status to something like “Executing” so other threads/services won’t get it again.

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

Sidebar

Related Questions

I'm trying to create a job in an ASP.NET (C#) form using Quartz.NET, and
We're using quartz (the java API) for job scheduling. This works well. Now I'm
I'm using an IJobListener in Quartz.NET to audit all job successes/failures. When a job
We're using Quartz.Net to schedule about two hundred repeating jobs. Each job uses the
I have an asp.net MVC web application that requires tasks to be scheduled. (A
I'm using it in Quartz.Net framework. Every Job(thread) has only one web request Here
I am using Quartz.Net to schedule task. I have tried like wise. Started a
I'm using Quartz.NET with a database, i.e. ADO.NET. Problem is, when my jobs are
I'm going to be using Quartz.NET for a Windows Service I am creating. I
greetings all i have a web application using (spring-hibernate) frameworks and when tried to

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.