Using async await still freezes GUI

后端 未结 2 1305
有刺的猬
有刺的猬 2021-02-20 02:23

I would like to handle long running operation in separate thread and return control back to GUI thread ASAP using async/await pattern as follows:

private         


        
2条回答
  •  花落未央
    2021-02-20 03:02

    You can use Task.Run or Task.Factory.StartNew to execute Test() or some long running and/or blocking operation on another thread:

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
        await Task.Run(() => Test());
        txtResult.Text = "Done!";
    }
    

提交回复
热议问题