我試過你的代碼並添加了一些輸出。
using (var webClient = new System.Net.WebClient())
{
Stopwatch timer = Stopwatch.StartNew();
String url = "http://bg2.cba.pl/realmIP.txt";
timer.Stop();
TimeSpan timespan = timer.Elapsed;
String tex1 = String.Format("{0:00}:{1:00}:{2:00}", timespan.Minutes, timespan.Seconds, timespan.Milliseconds/10);
timer = Stopwatch.StartNew();
String result = webClient.DownloadString(url); // slow as hell
timespan = timer.Elapsed;
String tex2 = String.Format("{0:00}:{1:00}:{2:00}", timespan.Minutes, timespan.Seconds, timespan.Milliseconds/10);
timer = Stopwatch.StartNew();
Stream stream = webClient.OpenRead(url);
timespan = timer.Elapsed;
String tex3 = String.Format("{0:00}:{1:00}:{2:00}", timespan.Minutes, timespan.Seconds, timespan.Milliseconds/10);
timer = Stopwatch.StartNew();
byte[] result2 = new byte[12];
int val = webClient.OpenRead(url).Read(result2, 0, 12); // even slower
timespan = timer.Elapsed;
String tex4 = String.Format("{0:00}:{1:00}:{2:00}", timespan.Minutes, timespan.Seconds, timespan.Milliseconds/10);
textBox1.Text = result;
t1.Text = tex1;
t2.Text = tex2;
t3.Text = tex3;
t4.Text = tex4;
}
結果如下
你的代碼似乎是好的。 檢查你的防火牆和所有參與
你有沒有使用Wireshark或類似的東西來看看在哪裏他的時間到了嗎? –
我沒有使用WS cuz我不知道如何操作它 –
@BartłomiejSobieszek讀入Wireshark然後 – Sybren