public void SortHelp(BlockingCollection <MyTask> tasksCollection) { while (tasksCollection != null) { if (tasksCollection.Contains(null)) { break; } MyTask task = tasksCollection.Take(); task.GoToSleep(); writer.WriteLine(task.value); } }