Beispiel #1
0
        public static List <TReturn> RunOnePerItem <T, TReturn>(Func <T, TReturn> act, List <T> Content)
        {
            Outputs = new ThreadOutputs <TReturn> ();

            Action <object> actOb = MakeObjConversionAct <T, TReturn> (act);

            List <Thread> threadsInUse = new List <Thread> ();
            List <T>      contentInUse = new List <T> ();

            foreach (T item in Content)
            {
                Thread th = new Thread(new ParameterizedThreadStart(actOb));
                threadsInUse.Add(th);
                contentInUse.Add(item);
                if (threadsInUse.Count == AppSettings.Processing.MAX_THREADS.Item)
                {
                    RunAndWait <T> (threadsInUse, contentInUse);
                }
            }
            if (threadsInUse.Count > 0)
            {
                RunAndWait <T> (threadsInUse, contentInUse);
            }

            return((Outputs as ThreadOutputs <TReturn>).GetOutputs());
        }
Beispiel #2
0
        public static List <TReturn> RunDividedList <T, TReturn>(Func <List <T>, TReturn> act, List <T> lst)
        {
            int tmax = AppSettings.Processing.MAX_THREADS.Item;

            Outputs = new ThreadOutputs <TReturn> ();

            Action <object> actOb = MakeObjConversionAct <List <T>, TReturn> (act);

            List <List <T> > starters     = new List <List <T> > ();
            List <Thread>    threadsToUse = new List <Thread> ();

            int chunk = lst.Count / tmax;
            int final = lst.Count % tmax;

            for (int i = 0; i < tmax; i++)
            {
                starters.Add(new List <T> ());
                if (i < tmax - 1)
                {
                    starters [i].AddRange(lst.GetRange(i * chunk, chunk));
                }
                else
                {
                    starters [i].AddRange(lst.GetRange(i * chunk, chunk + final));
                }
            }

            foreach (List <T> l in starters)
            {
                Thread th = new Thread(new ParameterizedThreadStart(actOb));
                threadsToUse.Add(th);
            }

            RunAndWait <List <T> > (threadsToUse, starters);

            return((Outputs as ThreadOutputs <TReturn>).GetOutputs());
        }