我的场景是:
我有20台服务器:
\server1.com
\server2.com
\server3.com
...
\server20.com
我的应用程序需要访问"最好的"服务器。"最佳"是指响应时间最短的。
如何在c#中检查此响应时间?
您可以使用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;