示例#1
0
        private static void ForkJoin(T objundertest, string[][] matrix, Action <T>[][] ops)
        {
            Thread[] threads = new Thread[ops.Length];

            // Create all threads
            for (int t = 0; t < threads.Length; t++)
            {
                int tt = t;
                threads[t] = new Thread(() =>
                {
                    for (int o = 0; o < ops[tt].Length; o++)
                    {
                        try
                        {
                            ChessAPI.TraceEvent(matrix[tt][o]);
                            ChessAPI.ObserveOperationCall(matrix[tt][o]);
                            ops[tt][o](objundertest);
                        }
                        catch (Exception e)
                        {
                            if (ChessAPI.IsBreakingDeadlock())
                            {
                                break;
                            }

                            ChessAPI.ObserveString("exception", e.Message);
                        }
                        ChessAPI.ObserveOperationReturn();
                    }
                });
            }

            // start all threads
            foreach (var t in threads)
            {
                t.Start();
            }

            // join all threads
            foreach (var t in threads)
            {
                t.Join();
            }
        }