DownloadStringAsync wait for request completion

前端 未结 6 1375
感动是毒
感动是毒 2020-12-10 13:41

I am using this code to retrieve an url content:

private ArrayList request(string query)
{
    ArrayList parsed_output = new ArrayList();

    string url = s         


        
6条回答
  •  隐瞒了意图╮
    2020-12-10 14:10

    i had the same problem with WP7 i solved this method.await is not working wp7 but if you use Action you will callback Async functions

         public void Download()
         { 
             DownloadString((result) =>
             {
                 //!!Require to import Newtonsoft.Json.dll for JObject!!
                 JObject fdata= JObject.Parse(result);
                 listbox1.Items.Add(fdata["name"].ToString());
    
             }, "http://graph.facebook.com/zuck");
    
        }
    
        public void DownloadString(Action callback, string url)
        {
            WebClient client = new WebClient();
            client.DownloadStringCompleted += (p, q) =>
            {
                if (q.Error == null)
                {
                    callback(q.Result);
    
                }
    
            };
    
            client.DownloadStringAsync(new Uri(url));
    
        }
    

提交回复
热议问题