Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

194
Vistas
C# Task.Delay(1).Wait() deadlocks but only if inside another Task

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?

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda