tags:

views:

86

answers:

2

I need to implement a function that contains a loop of instructions that should run every .01 second is there a way to implement a loop(e.g for each time step) that can do that thanks in advance

+4  A: 

You can generate a recurring event using the Timer class.

Robert Harvey
+8  A: 

You can use Timer class like this:

Timer t = new Timer(100);
t.Elapsed += (sender, e) =>
    {
        for (int i = 0; i < 10; i++)
        {
            // your loop
        }
    };

t.Start();
AS-CII
+1 for the example, although I also gave Robert +1 for having the answer first.
Steven Sudit
why this loop for (int i = 0; i < 10; i++) ??
Eng.Mohamed
It's a sample loop. It can be replaced by any kind of loop/code.
AS-CII
thanks you really save my life :D
Eng.Mohamed
Robert has answered before me, mark his answer as correct :)
AS-CII
AS-CII: you're answer is more complete, though
samy
Is the timer granularity really that good? It might be instructive to test this and see how many times per second you are actually getting called.
Eric Lippert