I need a function that waits for a specified number of DateTime.Ticks (about 155 000). Unfortunately, it works with the following function not really (waited about 300 000 ticks):
private void sleep_ticks(long t)
{
long _start = DateTime.Now.Ticks + t;
int i = 0;
do
{
i++;
Console.WriteLine((DateTime.Now.Ticks - _start) + " => " + i);
if (DateTime.Now.Ticks >= _start)
break;
} while (true);
Console.WriteLine((DateTime.Now.Ticks - _start) + " < " + t + " -- " + i);
Console.ReadLine();
}
I added some debug output :-) The last value would have to be close to 0.
Here is the output for sleep_ticks (1):
-1 => 1; -1 => 2; -1 => 3; -1 => 4; -1 => 5; -1 => 6; -1 => 7; -1 => 8; -1 => 9; -1 => 10;
-1 => 11; -1 => 12; -1 => 13; -1 => 14; -1 => 15; -1 => 16; -1 => 17; -1 => 18; -1 => 19;
-1 => 20; -1 => 21; -1 => 22; -1 => 23; -1 => 24; -1 => 25; -1 => 26; -1 => 27; -1 => 28;
-1 => 29; 156262 < 1 -- 29;
Does anyone have any idea why this might be, or how to fix it?
Thanks and regards Robert