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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:26:22+00:00 2026-05-30T07:26:22+00:00

I am new with C#. I am running a loop to send emails to

  • 0

I am new with C#. I am running a loop to send emails to subscribed users. I need to slow down the loop because I only want to send 10 email/second. Is using Thread.sleep good way to slow down the loop? please see code below.

            while (rdr.Read())
            {
                System.Threading.Thread.Sleep(100);

                //send email code here
            }

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-05-30T07:26:23+00:00Added an answer on May 30, 2026 at 7:26 am

    Why don’t you have a System.Timers.Timer that fires up every second and sends up to ten messages from your message queue every second.

    This way you really do have complete control over the process and are not guessing about speed/timings of your email sender.

    Perhaps something like this:

    public class EmailSender
    {
        private System.Timers.Timer _timer = new Timer(1000);
    
        public EmailSender()
        {
            _timer.Elapsed += (object sender, ElapsedEventArgs args) => SendEmail();
        }
    
        public void StartSender()
        {
            _timer.Enabled = true;
        }
    
        public void SendEmail()
        {
            // you *may* want to stop your timer here in case the send of the ten overruns 1s.
            _timer.Enabled = false;
    
            // code here to send UP TO ten emails
    
            // re-enable timer, if you stopped it above.
            _timer.Enabled = true;
        }
    }
    

    In short – no – your original approach is not good.

    • How do you know how long to make it sleep for to get 10 messages sent?
    • What happens if the machine is running slowly anyway?
    • What happens if you deploy to a faster machine?
    • etc..
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are migrating to a new server running Windows 2003 and IIS 6. When
I'm working on migration of data from a legacy system into our new app(running
Running the command generates new rails projects: $ rails generate controller home index The
I'm running into difficulty setting up a new project into source control. I've imported
I'm new to CakePHP and am just running through the configuration process, but am
I'm running Django 1.2 beta and trying out the new feature: message framework. http://docs.djangoproject.com/en/dev/ref/contrib/messages/
I'm running MOSS 2007 and have created a new site under an existing one
Running PHP debug session in Netbeans always opens as a new tab in browser
We were running Tarantino in a Nant build script but we're getting some new
I am fairly new to Objective-C and whilst running the Clang static analyser this

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.