C# - 获取 UDP 连接的往返时间
我当前正在通过 UdpClient 类连接到远程服务器以发送和接收数据。一切工作正常,但我希望能够获得发送和接收信息所需的总时间。最有效、最准确的方法是什么?
I am currently connecting to a remote server via the UdpClient class to send and receive data. Everything is working fine, but I would like to be able to get the total time it takes to send and receive the information. What would be the most efficient and accurate way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该分析您的应用程序以获得准确的结果。我推荐 dotTrace 4.5 性能。
另一种解决方案可以是秒表,就像 mvandersteen 建议的那样,但在这种情况下,我会推荐由 stackoverflow 开发人员开发的项目,可以在此处找到:http://code.google.com/p/mvc-mini-profiler/(假设您的应用程序是 MVC 3 项目)。
You should profile your application to get exact results. I would recommend dotTrace 4.5 Performance.
An alternative solution could be a Stopwatch, just like mvandersteen suggested, but in that case I would recommend a project developed by stackoverflow developers which can be found here: http://code.google.com/p/mvc-mini-profiler/ (assuming your application is an MVC 3 project).
可以尝试将代码包装在计时器中。粗鲁,但有效。
Could could try just wrapping your code in a timer. Crude, but effective.