All pastes #1879320 Raw Edit

BlockingThreader

public text v1 · immutable
#1879320 ·published 2010-06-08 21:33 UTC
rendered paste body
static class BlockingThreader {
    public static void Run(params Action[] f) {
        ManualResetEvent[] els=new ManualResetEvent[f.Length];
        for (int i=0; i<f.Length; ++i)
            new Helper(RunHelper).BeginInvoke(f[i],els[i],null,null);
        WaitHandle.WaitAll(els);
    }
    private static void RunHelper(Action f,ManualResetEvent sig) {
        f();
        sig.Set();
    }

    private static delegate void Helper(Action f,ManualResetEvent sig);
}