开发者

C# how to implement a loop with time step

开发者 https://www.devze.com 2023-01-21 04:52 出处:网络
I need to implement a function tha开发者_开发问答t 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

I need to implement a function tha开发者_开发问答t 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


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


You can generate a recurring event using the Timer class.

0

精彩评论

暂无评论...
验证码 换一张
取 消