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 :)