public static void Main(string[] args) { var threadPool = new MyThreadPool(5); var tasks = new List <IMyTask <int> >(); for (var i = 0; i < 10; ++i) { var j = i; tasks.Add(threadPool.QueueTask(() => Factorial(j))); } Thread.Sleep(1000); foreach (var task in tasks) { Console.WriteLine(task.Result); } tasks[0].ContinueWith((x) => { Console.WriteLine("New task is evaluating!"); return(x * x); }); threadPool.Shutdown(); }
/// <summary> /// Initializes a new instance of the <see cref="MyTask{T}"/> class. /// </summary> /// <param name="resultFunction">function that represent task</param> /// <param name="threadPool"> /// thread pool in which tasks from ContinueWith method /// are going to be evaluated /// </param> public MyTask(Func <TResult> resultFunction, MyThreadPool threadPool) { _resultFunction = resultFunction; _threadPool = threadPool; }