I can't figure out why Task.Delay(1).Wait() does not block the UI thread when called directly, but does when wrapped inside another Task that is then syncrhonously waited on.
Take for example this simple WPF window:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DoesNotDeadlock().Wait(); // <-- continues just fine
CausesDeadlock().Wait(); // <-- deadlocks
}
private Task DoesNotDeadlock()
=> Task.Delay(1);
private async Task CausesDeadlock()
=> await Task.Delay(1);
}
Why is the behavior different if we wait for the Delay Task directly vs if we wait for the Task that wraps it?