Precision Delay

Mar 15 2011 5:12 PM
I'm having a problem with my delay method.  The overhead of the delay function is causing my program to slow down way to much.  I go from a 0ms delay doing 7000 iterations in 1.466 seconds to a 1 ms delay doing 7000 iterations in 32.318 seconds.  The math doesn't add up.  Is there any way to get a more precise delay without slowing it down too much?

It's a multi-threaded app updating a simple graph in real-time:

        public static void DrawData(int[] data, int size)
        {
            myBuffer.Graphics.Clear(System.Drawing.Color.White);
            int x = 0;
            int y = 0;
            for (int i = 0; i < size; i++)
            {
                x = (i + 2) * width;
                y = 200 - data[i];                              
                myBuffer.Graphics.DrawLine(bluePen, x, 200, x, y);               
            }
            myBuffer.Render();          
            System.Threading.Thread.Sleep(delay);
        }

Answers (5)