My async Task always blocks UI

async-await, asynchronous, c#, dispatcher, multithreading

Solution

Try this:

private Task<double> JobAsync(double value)
{
    return Task.Factory.StartNew(() =>
    {
        for (int i = 0; i < 30000000; i++)
            value += Math.Log(Math.Sqrt(Math.Pow(value, 0.75)));

        return value;
    });
}

Problem

In a WPF 4.5 application, I don't understand why the UI is blocked when I used await + a task : ``` private async void Button_Click(object sender, RoutedEventArgs e) { // Task.Delay works great //await Task.Delay(5000); double value = await JobAsync(25.0); MessageBox.Show("finished : " + value.ToString()); } private async Task<double> JobAsync(double value) { for (int i = 0; i < 30000000; i++) value += Math.Log(Math.Sqrt(Math.Pow(value, 0.75))); return value; } ``` The await Task.Delay works great, but the await JobAsync blocks the UI. Why ? Thank you.

Original source