public void WaitAnyT()
        {
            STP smartThreadPool = new STP();

            bool success = false;

            IWorkItemResult <int>[] wirs = new IWorkItemResult <int> [5];

            for (int i = 0; i < wirs.Length; ++i)
            {
                wirs[i] = smartThreadPool.QueueWorkItem(new Func <int, int, int>(System.Math.Max), i, i - 1);
            }

            int index = STP.WaitAny(wirs);

            if (wirs[index].IsCompleted)
            {
                int result = wirs[index].GetResult();
                if (index == result)
                {
                    success = true;
                }
            }

            smartThreadPool.Shutdown();

            Assert.IsTrue(success);
        }
        public void WaitAny()
        {
            STP smartThreadPool = new STP();

            bool success = false;

            IWorkItemResult[] wirs = new IWorkItemResult[5];

            for (int i = 0; i < wirs.Length; ++i)
            {
                wirs[i] =
                    smartThreadPool.QueueWorkItem(new WorkItemCallback(this.DoSomeWork), null);
            }

            int index = STP.WaitAny(wirs);

            if (wirs[index].IsCompleted)
            {
                int result = (int)wirs[index].GetResult();
                if (1 == result)
                {
                    success = true;
                }
            }

            smartThreadPool.Shutdown();

            Assert.IsTrue(success);
        }
        public void WaitAnyWithTimeoutFailure()
        {
            STP smartThreadPool = new STP();

            bool success;

            IWorkItemResult[] wirs = new IWorkItemResult[5];

            for (int i = 0; i < wirs.Length; ++i)
            {
                wirs[i] =
                    smartThreadPool.QueueWorkItem(new WorkItemCallback(this.DoSomeWork), null);
            }

            int index = STP.WaitAny(wirs, 10, true);

            success = (index == WaitHandle.WaitTimeout);

            smartThreadPool.Shutdown();

            Assert.IsTrue(success);
        }