Микросекунда потребности задерживается в приложении.NET для регулировки уровня многоадресной передачи UDP

SC может сделать, все с сервисами... запускает, останавливает, проверяет, настраивает, и больше...

7
задан James Dunne 27 October 2009 в 15:14
поделиться

3 ответа

I would use stopwatch but would need a loop

read this to add more extension to the stopwatch, like ElapsedMicroseconds

or something like this might work too

System.Diagnostics.Stopwatch.IsHighResolution MUST be true

    static void Main(string[] args)
    {
        Stopwatch sw;
        sw = Stopwatch.StartNew();
        int i = 0;

        while (sw.ElapsedMilliseconds <= 5000)
        {
            if (sw.Elapsed.Ticks % 100 == 0)
            { i++; /* do something*/ }
        }
        sw.Stop();


    }
7
ответ дан 6 December 2019 в 10:51
поделиться

Very short sleep times are generally best achieved by a CPU spin loop (like the kind you describe). You generally want to avoid using the high-precision timer calls as they can themselves take up time and skew the results. I wouldn't worry too much about CPU pegging on the server for such short wait times.

I would encapsulate the behavior in a class, as follows:

  • Create a class whose static constructor runs a spin loop for several million iterations and captures how long it takes. This gives you an idea of how long a single loop cycle would take on the underlying hardware.
  • Compute a uS/iteration value that you can use to compute arbitrary sleep times.
  • When asked to sleep for a particular period of time, divide uS to sleep by the uS/iteration value previously computed to identify how many loop iterations to perform.
  • Spin using a while loop until the estimated time elapses.
9
ответ дан 6 December 2019 в 10:51
поделиться

Вы смотрели мультимедийные таймеры ? Вероятно, вы могли бы найти где-нибудь библиотеку .NET, которая обертывает вызовы API.

0
ответ дан 6 December 2019 в 10:51
поделиться
Другие вопросы по тегам:

Похожие вопросы: