how to execute certain class method no more than once per 100ms?

后端 未结 4 404
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-15 05:51

I\'m writing trading software and need to QoS one method that should not be executed more often than 10 times per second. As I\'m begginer in C# and almost not familar with

4条回答
  •  心在旅途
    2021-01-15 06:22

    There is always the System.Timer timer.

    That is probably easier to work with than the Stopwatch (which normally is used to measure how long time things take).

    Code:

        var timer = new System.Timers.Timer();
    
        // Hook up the Elapsed event for the timer using a lambda
        timer.Elapsed += (o, e) => Console.WriteLine("Timer elapsed");
    
        // Set the Interval to 100 ms
        timer.Interval = 100;
    
        // Start the timer.
        timer.Enabled = true;
    

    MSDN docs: http://msdn.microsoft.com/en-us/library/system.timers.timer(v=VS.100).aspx

提交回复
热议问题