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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:06:48+00:00 2026-05-27T08:06:48+00:00

I have a dll consumed by a service. Its basic job is to run

  • 0

I have a dll consumed by a service. Its basic job is to run every X minutes and perform some system checks.
In my dll I have a top level class that declares a System.threading.timer and a Timercallback.
The constructor for the class initialises the timerCallback with my thread function.
In my “Onstart” handler I initialise the timer with the timercallback and set the next time to fire and interval time. In my case its every 10 minutes.
Usually in these 10 minute checks there is nothing to do but the service is forced to do something at least once every day at a set time.

My problem: I am finding that during testing, the time the daily check is carried out every day is slowly drifitng away from the desired start time of 8.30. e.g. over about 20 odd days my time has drifted from 08.30 to 08.31.35. It drifts about 4 – 6 seconds every day.

My question: does anyone know why the time is drifting like this and how can I make it stick to its allotted time?

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-27T08:06:49+00:00Added an answer on May 27, 2026 at 8:06 am

    The time “drifts” because the timer is simply not that precise. If you need to run your code as closely as possible to a certain interval, you can do something like this:

    public void MyTimerCallback(object something) {
        var now = DateTime.UtcNow;
        var shouldProbablyHaveRun = new DateTime(
            now.Year, now.Month, now.Day,
            now.Hour, now.Minute - (now.Minute % 10), 0);
        var nextRun = shouldProbablyHaveRun.AddMinutes(10.0);
    
        // Do stuff here!
    
        var diff = nextRun - DateTime.UtcNow;
        timer.Change(diff, new TimeSpan(-1));
    }
    

    …assuming you are using a System.Threading.Timer instance. Modify the example if you are using any other type of timer (there are several!).

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

Sidebar

Related Questions

I have DLL and application that will call some function in this dll. For
I have a DLL with some COM objects . Sometimes, this objects crashes and
I have to consume some C# dll's under a linux host through java. Rewriting
I have DLL that run on server and I can't debug it for many
I need to consume a WCF service from a DLL, hence i don't have
I have an DLL that has this in its h file: extern C __declspec(dllexport)
I have a DLL which takes care of custom drawing for some special glass
I have A.DLL that depends on B.DLL. A.DLL contains some initialization code ( DllMain
We have a DLL used as the middle layer between our website front end
I have a dll that must be useable from C etc, so I cant

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.