My async Task always blocks UI

前端 未结 2 1122
广开言路
广开言路 2021-01-04 06:21

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, RoutedEve         


        
2条回答
  •  难免孤独
    2021-01-04 06:59

    Try this:

    private Task 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;
        });
    }
    

提交回复
热议问题