0
我正在使用WebClient類從遠程服務器獲取數據的應用程序。問題是我不能分辨誤差爲: (1)連接超時 (2)的URL不存在 (3)無網絡連接如何知道WebClient/DownloadStringCompletedEventArgs的錯誤異常類型?
這裏是代碼片段:
WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
client.DownloadStringAsync(new Uri(url, UriKind.Absolute));
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null && !e.Cancelled)
{
}
else
{
MessageBox.Show(e.Error.ToString()); // Return System.Net.WebException
MessageBox.Show(e.Error.Data.Count + ""); // return 0
/*foreach (DictionaryEntry de in e.Error.Data)
MessageBox.Show(de.Key + ", " + de.Value);*/
}
}
我需要知道DownloadStringCompletedEventArgs的錯誤類型,因爲我將向用戶顯示自定義的錯誤消息。請幫忙,謝謝!
感謝nkchandra,你知道在哪裏可以找到e.Error.Message的完整列表? –