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
+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
2010-10-20 22:06:30
+1 for the example, although I also gave Robert +1 for having the answer first.
Steven Sudit
2010-10-20 22:08:05
why this loop for (int i = 0; i < 10; i++) ??
Eng.Mohamed
2010-10-20 22:10:35
It's a sample loop. It can be replaced by any kind of loop/code.
AS-CII
2010-10-20 22:11:50
thanks you really save my life :D
Eng.Mohamed
2010-10-20 22:15:10
Robert has answered before me, mark his answer as correct :)
AS-CII
2010-10-20 22:24:59
AS-CII: you're answer is more complete, though
samy
2010-10-20 22:27:40
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
2010-10-20 23:43:36