/// <summary> /// Main method /// </summary> public void Run() { var sentences = _textManager.GetSentences(_fileName); for (var i = 0; i < sentences.Length; i++) { var index = i % _threadCount; AddQueue(index, sentences[i]); } Task[] workers = new Task[_threadCount]; for (int i = 0; i < _threadCount; ++i) { int workerId = i; Task task = new Task(() => Worker(workerId)); workers[i] = task; task.Start(); AddThreadToDic(workerId); } Task.WaitAll(workers); }