On Tue, Apr 3, 2012 at 12:44 PM, MojoDK <[email protected]> wrote: > Hi, > > I have this code: > > string url="bla"; > ThreadPool.QueueUserWorkItem (delegate { > try { > WebClient client = new WebClient(); > string html = client.DownloadString(url); > client.Dispose(); > client = null; > // Do something with the result. > } catch (WebException e) {} > }); > > ... but it seams to slow/block the main UI anyway somehow. > > What is best practice in Monotouch to fetch a webpage HTML without blocking > the UI? I need to fetch like 60 webpages (actually it's JSON results) as > fast as possible and today I spin up 2 threads at a time.
Just use the async version of DownloadString. As a side note, WebClient does not scale very well. If you want to launch more than one simutaneous request, I would go with HttpWebRequest+asynchronous methods there. http://msdn.microsoft.com/en-us/library/ms144202.aspx -Gonzalo _______________________________________________ MonoTouch mailing list [email protected] http://lists.ximian.com/mailman/listinfo/monotouch
