有时候服务器关机,服务器上的文件丢失等问题。所以,我想在使用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