Firing 100 requests at once will probably cause trashing and excessive memory usage.
If you can live with doing a request at a time you could chain one request after the other from the finished callback. Limiting to a given degree of parallelism is tricky, but possible using callbacks as well. You definitely needs to experiment how each approach works in practice as they all have tradeoffs. On Wed, Feb 22, 2012 at 6:12 PM, MojoDK <[email protected]> wrote: > Hi, > > I need to do about 100 WebClient.DownloadString("xxxxx") as fast as > possible. > > Threading is not my strongest side, so I ask for your help. > > What is best practice in MT for doing 100 webrequest as fast as possible? > > My idea was something like (I haven't tested it)... > > private void StartWebRequets () { > for (int i = 0; i < 100; i++) { > ThreadPool.QueueUserWorkItem(DoQueryWeb, i); > } > } > > private void DoQueryWeb(object state) { > int i = state as int; > WebClient client = new WebClient(); > string html = client.DownloadString("my url"); > InvokeOnMainThread(delegate { > // Do main thread stuff here > }); > } > > My worries is that firing 100 webrequests will kill the app. How would you > solve it? Can I tell ThreadPool to only do like 3-4 at a time? > > Thanks!! > Mojo > > -- > View this message in context: > http://monotouch.2284126.n4.nabble.com/Threading-best-practice-tp4411605p4411605.html > Sent from the MonoTouch mailing list archive at Nabble.com. > _______________________________________________ > MonoTouch mailing list > [email protected] > http://lists.ximian.com/mailman/listinfo/monotouch >
_______________________________________________ MonoTouch mailing list [email protected] http://lists.ximian.com/mailman/listinfo/monotouch
