[英]Get best access response time from a server directory C#
My scenario is:我的场景是:
I've 20 servers:我有 20 台服务器:
\\server1.com
\\server2.com
\\server3.com
...
\\server20.com
My application need access the "best" server.我的应用程序需要访问“最佳”服务器。 "The best" means the one with the smallest response time.
“最好”是指响应时间最短的那个。
How I can check this response time in C#?如何在 C# 中检查此响应时间?
You can calculate response time using HttpWebRequest
and HttpWebResponse
.您可以使用
HttpWebRequest
和HttpWebResponse
计算响应时间。
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(myUri);
System.Diagnostics.Stopwatch timer = new Stopwatch();
timer.Start();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
response.Close();
timer.Stop();
TimeSpan timeTaken = timer.Elapsed;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.