Mohamed
Mohamed

Reputation: 1597

C# how to implement a loop with time step

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

Upvotes: 3

Views: 5504

Answers (2)

as-cii
as-cii

Reputation: 13049

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();

Upvotes: 8

Robert Harvey
Robert Harvey

Reputation: 180958

You can generate a recurring event using the Timer class.

Upvotes: 4

Related Questions