I have the block of code below where I update a list of users in an async foreach block. Then I have to parse that list of users to another service. The problem is even if I set the users value isRegistered to true, when it gets to the _secondService.UpdateUsers function, the value is still false.
The secondService function has to be outside the foreach. I understand it has something to do with the async, but I have also awaited the second service. Is there a workaround for this?
userList.ForEach(async user =>
{
if (user.isRegistered == false)
{
if (await _service.RegisterUser(user))
{
user.isRegistered = true;
}
}
});
await _secondService.UpdateUsers(userList);