multithreading - C# Timer.Interval Pattern with 40ms? -
i'd use 3 or 4 c# timers interval 40ms (to work image data 1000/25 = 40).
according msdn seems pattern perform task every 40ms. default interval 100ms.
in real life, i'd know if 40ms still ok ? or if should use thread design pattern ? wakeup/sleep behavior near cpu free ?
there no special relevance 100 msec default, can change needed.
you need pick values if want interval that's consistent 1 machine another. accuracy of timer class affected default operating system clock interrupt rate. on windows machines, interrupt occurs 64 times per second. equal 15.625 milliseconds. there machines have higher rate, go low 1 msec. side-effect of other programs changing interrupt rate. timebeginperiod() winapi function , has global effect.
so best intervals pick ones multiple of 15.625 , stay below that. chosen interval repeats on machine. makes choices:
- 15
- 31
- 46
- 62
- etc.
your best bet aiming near 40 msec therefore 46. accurate 1.4% on machine. pick 45 myself, nice round number.
do beware actual intervals can arbitrary longer if machine under heavy load or have lot of active threadpool threads in program.
Comments
Post a Comment