有時候服務器關機,服務器上的文件丟失等問題。所以,我想在使用Dispatcher線程更新UI上的內容時捕獲或捕獲由HttpWebRequest引發的異常。如何獲得HttpWebrequest爲Wp7引發的異常/錯誤
下面的代碼無法捕獲錯誤並顯示在MessageBox.show()中。任何人都可以告訴我我需要做什麼?謝謝
HttpWebRequest webReq;
HttpWebResponse webResp;
public void GetInfo(string Url)
{
webReq = (HttpWebRequest)HttpWebRequest.Create(Url);
try
{
webReq.BeginGetResponse(OnGetBuffer, this);
}
catch (Exception e)
{
}
}
public void OnGetBuffer(IAsyncResult asr)
{
webResp = (HttpWebResponse)webReq.EndGetResponse(asr);
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
Stream streamResult = webResp.GetResponseStream();
try
{
}
catch (Exception)
{
}
});
}
@Richard施奈德我希望更多的人意識到了這一點 – harryovers 2011-03-24 00:48:33