Wait for HttpWebRequest.BeginGetResponse to finish in Windows Phone 7

后端 未结 6 2075
星月不相逢
星月不相逢 2021-02-10 20:05

I\'m trying to use the async HttpWebRequest in Silverlight for Windows Phone. All works perfect until I get to the where I should call

private stati         


        
6条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-10 21:02

    You probably want to move allDone.Set() outside the try..catch. Otherwise the event will never be set if there's an exception and the thread that started the async operation will hang. That is, you want to write:

    try
    {
        request = (HttpWebRequest)asynchronousResult.AsyncState;
        response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
    }
    catch (Exception e)
    {
        Debug.WriteLine("Got Exception in GetResponseCallback: " + e.Message);
    }
    
    allDone.Set();
    

提交回复
热议问题