I'm making simple stroboscope attached to computer. I have Loop Like that:
double SleepTime = 1000 / Hz;
while ()
{
BlinkAll();
Thread.Sleep((int)SleepTime);
}
But this is very inaccurate. If Hz = 666 than SleepTime = 1.5 and (int)SleepTime = 1
this means that on output I get 1000Hz not 666Hz This is big diffrence.
How to fix this?
P.S.
This example is still not to accurate. It's better but not good in any way:
double SleepTime = 1000 / Hz;
Thread.Sleep((int)SleepTime + 0.5)