My thoughts about this are as follows. Investigate if your web requests
can be done asynchronously. If that is possible you could do something
along this road:

-Have a queue with the 100 requests.
-Start a background thread with that keeps an eye on how many requests
are in progress
-Inside the thread start the async requests one by one untill you have
reached your limit.
-When each of the requests call back update the status of how many
requests are in progress.
-End the whole thing when you are done processing.

I think that it how I would approach it.
From: MojoDK
Sent: 22/02/2012 21:13
To: [email protected]
Subject: [MonoTouch] Threading best practice
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

Reply via email to