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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:37:42+00:00 2026-05-16T12:37:42+00:00

According to the documentation the maximum dueTime value is 4294967294 milliseconds. But if you

  • 0

According to the documentation the maximum dueTime value is 4294967294 milliseconds. But if you set the timer to this value it fires a callback immediately.

Run the below program and click “c” – the callback will fire immediately, click “o”, it will fire after 49 days, click “v” it will fire after 1s. Is this a bug or am I doing something wrong?

using System;
using System.Threading;

namespace Test
{
    class Program
    {
        private static bool isRunning;
        private static Timer t;

        static void Main(string[] args)
        {
            t = new Timer(OnTimerCallback, null, Timeout.Infinite, Timeout.Infinite);
            isRunning = true;
            while (isRunning)
            {
                var command = Console.ReadKey();

                switch (command.KeyChar)
                {
                    case 'q':
                        isRunning = false;
                        break;
                    case 'c':
                        t.Change(TimeSpan.FromMilliseconds(4294967294), TimeSpan.FromMilliseconds(-1));
                        break;
                    case 'o':
                        t.Change(TimeSpan.FromMilliseconds(4294000000), TimeSpan.FromMilliseconds(-1));
                        break;
                    case 'v':
                        t.Change(TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(-1));
                        break;
                }
            }
            Environment.Exit(0);
        }

        private static void OnTimerCallback(object x)
        {
            Console.WriteLine("Timer callback");
            t.Change(TimeSpan.FromMilliseconds(4294967294), TimeSpan.FromMilliseconds(-1));
        }
    }
}

UPDATE

If you set timer to the max dueTime value in a callback it will not fire immediatelly and will work as expected 🙂

  • 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-16T12:37:43+00:00Added an answer on May 16, 2026 at 12:37 pm

    This looks like a race in the CLR’s implementation of the timer. I need to wave my hands at the exact cause, I don’t really understand how it can go wrong. At least from looking at the SSCLI20 source code (clr\src\vm\win32threadpool.cpp), there’s a good chance that this is no longer accurate with the currently shipping code.

    I can repro the problem easily by setting a breakpoint at the Change() call but not when I let the code run without a break. It behaves like it calculates the due time from the last observed value returned by GetTickCount() instead of the current value. Adding 0xfffffffe to that stale value then calculates a time that already expired. The tick count only has 32-bits of resolution. I think the real race is in the calculation of how long to SleepEx() to wait for the next time due event, but that’s a guess.

    It is possible that this race can occur also if you don’t use the debugger to pause the timer thread. Although it would probably be rare. I’d have to recommend you stay away from any value close to 0xfffffffe to be sure this won’t happen. No hardship there, sleeping for 24 days is not less efficient than sleeping for 49 days 🙂 Implement longer intervals by counting sleep periods yourself.

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

Sidebar

Related Questions

according the documentation borderThickness is an applicable style, but when I try to set
According to the documentation for -[UIView setNeedsLayout] : Because this method does not force
According to documentation Default implementation does nothing. But... I throw exception from drawRect method
According to documentation , On success, zero is returned but none of the functions
According to the Sun's documentation on ServerSocket: The maximum queue length for incoming connection
According documentation Google App Engine could send mail but from restricted list of addresses
There's setDoOutput() in URLConnection . According to documentation I should Set the DoOutput flag
According to documentation , git update-index --refresh does this: Looks at the current index
According to documentation , all I need for Jersey client is jersey-bundle.jar . But
according documentation: On success, the function returns the converted integral number as a long

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.