Even if TPL , as Ralph suggested, is not available in Silverlight, I really like the Task model ... So why not write which will work the same way.
using System;
using System.Threading;
using System.Linq;
public class Task {
ManualResetEvent _mre = new ManualResetEvent(false);
public Task(Action action) {
ThreadPool.QueueUserWorkItem((s) => {
action();
_mre.Set();
});
}
public static void WaitAll(params Task[] tasks) {
WaitHandle.WaitAll(tasks.Select(t => t._mre).ToArray());
}
}
Then you can use this very similar to TPL:
int param1 = 1;
int param2 = 2;
Task.WaitAll(
new Task( () => DoSomething(param1, param2) ),
new Task( () => DoSomething(param1, param2) )
);
Under the covers, ThreadPool is responsible for limiting the threads in the system to a reasonable value.
source
share