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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:36:56+00:00 2026-05-26T02:36:56+00:00

I was wondering if anyone knows a good way to regulate how many emails

  • 0

I was wondering if anyone knows a good way to regulate how many emails are sent through C#?

Here is my scenario. I have a windows service that monitors three other windows services. I am using a service controller to get the status of all 3 services and if the status of any of these services change to stopped, it sends an email. My issue is, I run this on a 60 second timer so it sends an email every 60 seconds until someone starts the service back up.

My first thought was, when first email is sent, create a text file and use a counter to number it. Do this while counter < 6 so I will only receive 5 emails max. I think this will work but it seems kind of silly.

Does anyone have an alternative to this or should I just go with my first thought and perform clean up on the files?

Thank you

EDIT: The reason that I was trying to limit the number of emails sent is because the people who receive these emails do not react very quickly. At the same time, those who handle Exchange do not want the service to spam people. I felt 5 would be enough to appease both sides.

  • 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-26T02:36:56+00:00Added an answer on May 26, 2026 at 2:36 am

    I would suggest that you should track the down time of each service.

    So every 60 seconds you check, if a service is down, store the DateTime that the service is down. The on the next 60 second interval you can check to see if the service was already down. i.e. you can tell if the service just went down or has been down a while. You can also add another flag to determine if the the last check was UP or DOWN.

    Then when the program first finds the service down it can send the email. Once the service is back up it can reset this flag values so the next down time it knows to send a new email.

    You can then also use these flags to delay email frequency if desired. Just add a new DateTime field for LastEmailSentTime and compare that with whatever interval you want for error emails (say 10 minutes)

    Hope that gives you some ideas

    EDIT: Some Sample…

    bool ServiceWasDown = false;
    DateTime ServiceDownTime = DateTime.Now;
    DateTime LastEmailTime = DateTime.Now;
    
    void OnTimerElapsed()
    {
       if(IsServiceDown())
          ServiceDown();
       else
          ServiceUp();
    }
    
    void ServiceDown()
    {
       if(ServiceWasDown)//already know about service
       {
          //if LastEmailTime more than 10 minutes ago send another email and update LastEmailTime
       }
       else//service just went down
       {
          //send new email
          LastEmailTime = DateTime.Now;
          ServiceWasDown = true;
          ServiceDownTime = DateTime.Now;
       }   
    }
    
    void ServiceUp()
    {
       ServiceWasDown = false;   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if anyone knows of any good Open Source distributed computing projects?
I was wondering if anyone knows of some good community distributed custom DDL templates
Just wondering if anyone knows of a way to implement a Typed Nullable Type
I was wondering if anyone knows a good library for tessellating a hyperbolic plane
Hiya! I was wondering if anyone knows of some good Android Animation XML examples
Was wondering if anyone knows a good alternative to tinymce? I find that it
I was wondering if anyone knows about good tutorials or articles describing methods of
I was wondering if anyone knows about a good article which describes dividing workload
Wondering if anyone has written or come across a good way to log to
I am just wondering if anyone know of some good tutorials on the Internet

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.