Need microsecond delay in .NET app for throttling UDP multicast transmission rate

后端 未结 6 1669
遇见更好的自我
遇见更好的自我 2020-12-15 12:37

I\'m writing a UDP multicast client/server pair in C# and I need a delay on the order of 50-100 µsec (microseconds) to throttle the server transmission rate. This helps to a

6条回答
  •  旧时难觅i
    2020-12-15 12:52

        static void udelay(long us)
        {
            var sw = System.Diagnostics.Stopwatch.StartNew();
            long v = (us * System.Diagnostics.Stopwatch.Frequency )/ 1000000;
            while (sw.ElapsedTicks < v)
            {
            }
        }
        static void Main(string[] args)
        {
            for (int i = 0; i < 100; i++)
            {
                Console.WriteLine("" + i + " " + DateTime.Now.Second + "." + DateTime.Now.Millisecond);
                udelay(1000000);
            }
        }
    

提交回复
热议问题