(async/await) I don’t know why it’s still looping

After the statement is executed to the second await Task.Delay, it does not continue to await Task.Yiedl() but to Debug.Log("123").

 public async void DoSomeThing()
 {
     await SomeThing();
 }

 public async Task SomeThing()
 {     await Task.Delay(1000) ;
     Debug.Log("123");
     foreach (int unitID in UnitsID)
     {
         dataBaseSO.UnitSpawn(unitID);
     }
     await Task.Delay(1000);
     await Task.Yield();
     Debug.Log("456");
 }

1 Answer

1

Async await methods do not loop unless you use a loop or you call it somehow again. How about adding a Debug.Log at the very start of the “SomeThing” method? When it’s called, check the callstack in order to know from where / who is calling it. We can’t do that for you since we don’t even know from where you call your DoSomething method.