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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:42:36+00:00 2026-05-29T21:42:36+00:00

In my previos question I asked about rounding time value to nearest third-minute. Well

  • 0

In my previos question I asked about rounding time value to nearest third-minute.
Well now I have some issues with my System.Threading.Timer that must work when is third-minute time is come. I Do following:

private System.Timers.Timer WorkTimer;
//...
public void StartProccessing()
{
WorkTimer = new System.Timers.Timer();
WorkTimer.AutoReset = false;
WorkTimer.Elapsed += new ElapsedEventHandler(WorkTimer_Elapsed);
StartWorkTimer();
}
//...
private void StartWorkTimer()
        {
            WorkTimer.Interval = (CurrentTime.AddMinutes(3) - DateTime.Now).TotalMilliseconds;
            WorkTimer.Start();
        }
void WorkTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            WorkTimer.Stop();
            this.ProcessData(this.CurrentTime);
            StartWorkTimer();
        }

Problem is that the when timer started – it is not work in first third-minute time, its begin working after second third-minute time. For example:
Timer is started at 15.02.2012 12:20:32.871, in 15.02.2012 12:21:00.000 it must work WorkTimer_Elapsed, but its begin from 15.02.2012 12:24:01.871. How to fix this?
I fix my CurrentTime time (from previos question):

private DateTime CurrentTime
        {
            get
            {
                DateTime now = DateTime.Now.AddSeconds(30);
                DateTime val;
                val = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0)
                     .AddMinutes(((now.Minute) / 3) * 3 - now.Minute);
                return val;
            }
        }
  • 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-29T21:42:39+00:00Added an answer on May 29, 2026 at 9:42 pm

    The problem here is that you round to the nearest 3rd minute, but for your timer to work you have to use the most recent one.

    So, if you remove the AddSeconds(30), your timer should work as expected.

    On a side note: your rounding algorithm should add 90 seconds (as that’s the half of 3 minutes) rather than 30. If you’re adding 30 seconds to 12:31:50, you’d end up with 12:30:00, but it should be 12:33:00 instead.

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

Sidebar

Related Questions

This is a continuation question from a previous question I have asked I now
I have asked several questions about Zend and its search functions. Now after further
In my previous question on this portal, I had asked about some insight about
I asked a previous question about mapping an enumerated value on a table using
I have a challenging problem I've been battling for some time now. The Problem:
So in a previous question I asked about implementing a generic interface with a
In a previous question I asked about how to group XML elements logically, and
This stems from a previous question I asked - about a write conflict with
This is a follow up question to a previous question I asked about calculating
In a previous question, I asked about various ORM libraries. It turns out Kohana

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.