Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!