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

  • Home
  • SEARCH
  • 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 6798117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:41:29+00:00 2026-05-26T18:41:29+00:00

I need to make a function that works on it is won thread to

  • 0

I need to make a function that works on it is won thread to do announcements in its determinate time, for example:

  • “Visit our website at : ….” set to run every 5 minutes
  • “Check your place on the rank at : ….” set to run every 10 minutes

I am a bit confused if I should use a thread timer or a thread while with sleep and how to calculate when every announcements should run.

To get started I was considering the a list of a class to hold each announcement to be made, something like List<MyTimer> with the class as:

public MyTimer
{
    public string Announcement { get; set; }
    public int Interval { get; set; } // if interval is 0 means 
                                      // it will run just once
    public bool hasSpecificTime { get; set; } // if this is true then will run
                                              // only once at the SpecificTime
    public bool Done { get; set; }
    public DateTime SpecificTime { get; set; }
}

Specific time announcements will be removed after used.

As for the thread I was thinking of using something like this:

Timer = new System.Threading.Timer(TimerCallback, null, 0, 1000);

private void TimerCallback(object state)
{
    foreach (var item in timerList)
    {
        // not sure how to handle the intervals of each continuous announcement
        // some code here for the the above

        // Not sure if this would work either because of the milliseconds etc
        // on the DateTime
        if (item.hasSpecificTime && !item.Done && SpecificTime == DateTime.Now)
        {
            SendAnnouncement(item.Announcement);
            item.Done = true;
        }
    }
}
  • Is my implementation OK for what I need ?

  • How do I handle the interval and times within the function as I said in the question I am not sure on how to get it calculated to send it on the correct time ?

  • 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-26T18:41:30+00:00Added an answer on May 26, 2026 at 6:41 pm

    You need to change

    item.hasSpecificTime && !item.Done && SpecificTime == DateTime.Now
    

    to

    item.hasSpecificTime && !item.Done && SpecificTime <= DateTime.Now
    

    otherwise you will almost all events.

    If your timerList grow large you should move completed items to a separate list instead to avoid looping through lots of completed items all the time.

    Edit
    You also need to increase SpecificTime with Interval for the recurring events.

    You can create more elaborate schemes, but your code is simple to read and understand and that is very important.

    One scheme you can use is to store the MyTimer instances in an ordered queue where you keep the closest SpecifiedTime first. You can then schedule the TimerCallback to the duration until the first element in the queue instead of repeatedly polling a complete list. You need to have some more book-keeping too. If you insert a new item in the queue and that item happens to be the next to be executed (comes first in the queue) you need to cancel and restart your timer.

    This is more “elegant”, but is only necessary if you have lots of events and suffer from performance issues (or the 1000 ms resolution is not granular enough).

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

Sidebar

Related Questions

I need to make a Function that receives a Session Key and a Session
I need to make a stored procedure or function that returns a set of
We need to make our enterprise ASP.NET/NHibernate browser-based application able to function when connected
I need to make one function in a module platform-independent by offering several implementations,
I need to make this function work everywhere, except IE6-7 $(function(){ window.scrollTo(0,300); }) Please
I need to make a 2D convex hull function for a class assignment and
What would i need to put in the SortIP function to make the custom
I'm going to create mobile application that works with CommuniGate Pro server. For example,
I'd like to make a node.js function that, when calls, reads a file, and
I need to make sure that when someone reloads or closes my page, their

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.