public void CallMultiple(Action <Object, ContextSwitcher> act, Int32 count, Object[] state) { ExecutingCount = count; ContextSwitcherHost host = new ContextSwitcherHost(count); ContextSwitcher[] switchers = new ContextSwitcher[count]; for (Int32 I = count - 1; I >= 0; --I) { switchers[I] = new ContextSwitcher(I); if (I < count - 1) { switchers[I].NextSwitcher = switchers[I + 1]; } } switchers[count - 1].NextSwitcher = switchers[0]; for (Int32 I = 0; I < count; ++I) { Thread t = new Thread(CallerFunction); t.Name = "ParallelFunctionTester [" + I + "]"; t.Start(new ExecState(act, switchers[I], state[I], t)); } switchers[0].Signal(); while (ExecutingCount > 0) { Thread.Sleep(300); } //Now raise the exception if needed StringBuilder sb = new StringBuilder(); StringBuilder detail = new StringBuilder(); for (Int32 I = 0; I < count; ++I) { if (switchers[I].AssertionFail) { sb.AppendFormat("Function number {0} has failed:\n", I); detail.AppendFormat("Message for function number {0}:{1}\n", I, switchers[I].FailedAssertion); } } if (sb.Length > 0) { Assert.Fail(sb + "\n" + detail); } }
public void CallMultiple(Action<Object, ContextSwitcher> act, Int32 count, Object[] state) { ExecutingCount = count; ContextSwitcherHost host = new ContextSwitcherHost(count); ContextSwitcher[] switchers = new ContextSwitcher[count]; for (Int32 I = count - 1; I >= 0; --I) { switchers[I] = new ContextSwitcher(I); if (I < count - 1) { switchers[I].NextSwitcher = switchers[I + 1]; } } switchers[count - 1].NextSwitcher = switchers[0]; for (Int32 I = 0; I < count; ++I) { Thread t = new Thread(CallerFunction); t.Name = "ParallelFunctionTester [" + I + "]"; t.Start(new ExecState(act, switchers[I], state[I], t)); } switchers[0].Signal(); while (ExecutingCount > 0) Thread.Sleep(300); //Now raise the exception if needed StringBuilder sb = new StringBuilder(); StringBuilder detail = new StringBuilder(); for (Int32 I = 0; I < count; ++I) { if (switchers[I].AssertionFail) { sb.AppendFormat("Function number {0} has failed:\n", I); detail.AppendFormat("Message for function number {0}:{1}\n", I, switchers[I].FailedAssertion); } } if (sb.Length > 0) Assert.Fail(sb + "\n" + detail); }