public void CheckingTheNumberOfThreadsTest()
        {
            int numberOfEvaluatedTasks = 0;

            for (int i = 0; i < 20; i++)
            {
                threadPool.AddTask(() =>
                {
                    Interlocked.Increment(ref numberOfEvaluatedTasks);
                    Thread.Sleep(3000);
                    return(0);
                });
            }

            Thread.Sleep(500);
            Assert.AreEqual(Environment.ProcessorCount, numberOfEvaluatedTasks);
        }
            /// <summary>
            /// Add new task based on result of this task.
            /// </summary>
            /// <param name="func">New function</param>
            /// <returns>New task</returns>
            public IMyTask <TNewResult> ContinueWith <TNewResult>(Func <TResult, TNewResult> func)
            {
                if (threadPool.cancelTokenSource.IsCancellationRequested)
                {
                    throw new InvalidOperationException("Thread pool is closed.");
                }
                var newTask = new MyTask <TNewResult>(() => func(Result), threadPool);

                lock (locker)
                {
                    if (IsCompleted)
                    {
                        return(threadPool.AddTask(() => func(Result)));
                    }
                    localQueue.Enqueue(newTask.Counting);
                    return(newTask);
                }
            }