I have a function that has two parts. need all the success of the first part before execute the second part.
Such as:
ConcurrentDictionary<string, string> _dic = new ConcurrentDictionary<string, string>();
var _taskList = new List<Task>();
foreach (var item in someDataList)
{
_taskList.Add(new Task(async () =>
{
var result = await _req.ExecuteAsync(someParams).ConfigureAwait(false);
_dic.TryAdd(result.data, result.data);
}
}
_taskList.ForEach(t => t.Start());
await Task.WhenAll(_taskList.ToArray()).ConfigureAwait(false);
if (_dic.Count == List.count()
{
//execute part 2.
}
not waiting for all tasks to be completed, there is no data in the dictionary at any time. and i try:
while (true)
{
foreach (var item in _taskList)
{
if (item.Status == TaskStatus.Running)
goto continueWait;
}
}
but it didn't work either.
Why is that? What should I do?