Search Issue Tracker
Fixed in 2018.2.X
Fixed in 2018.1.X
Votes
0
Found in
Issue ID
1004428
Regression
No
Task.Delay(0) Hangs with Async Await
Reported hangs with Async/Await
https://forum.unity.com/threads/task-yield-task-delay-0-hang.518045/
using System.Threading.Tasks;
using UnityEngine;
public class Test : MonoBehaviour
{
void Start()
{
TestAsync();
}
async void TestAsync()
{
int i = 0;
while (true)
{
Debug.Log($"### TestAsync: {++i}");
await Task.Delay(1); // ok
// await Task.Delay(0); // hang!
// await Task.Yield(); // hang!
}
}
}
Update:
I've looked at this issue and found that Task.Delay(0) runs synchronously. You can find details about this behavior on stackoverflow https://stackoverflow.com/questions/36939006/not-using-await-task-delayx-x0-makes-ui-thread-freeze
We have made one change due to this report however. Currently, when processing async/await continuations, we currently process the continuations that are spawned from existing continuations. This is why Task.Yield() would hang. Instead soon (once the changes land in 2018.1), if an "awaited" function calls await again, that continuation will be processed on to the next pass through the player loop. I should mention that we're also considering changes to where we process continuations in the playerloop (currently fixedupdate) since this behavior seems inconsistent in some ways with how other .NET implementations work.
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Assigned font's bold/font-weight styles render using Default Font's assets when Default Font has corresponding style assets defined in TMP Settings
- "Modifying the parent of a VisualElement while it’s already being modified is not allowed" error is thrown when entering text and pressing tab in the Search window
- Mesh colliders are not updating their positions of bounds correctly
- Images are missing from the "Open the sprite editor" documentation for 6.0, 6.1 and 6.2
- The previous element in the array is modified when assigning an Asset to a new element of AssetReferenceT
Add comment