C# wait until its completed

后端 未结 2 1906
逝去的感伤
逝去的感伤 2021-01-29 02:27

I have some code, and I have noticed it makes my app freeze. I\'m looking for a solution that is better than mine.

How to wait for values which I don\'t know when I rece

2条回答
  •  执笔经年
    2021-01-29 03:07

    I think best way to use async await. In C#, asynchronous programming with async await is very easy. Code looks like synchronous.

    private async void StartButtonClick(object sender, RoutedEventArgs e)
    {
       // Starting new task, function stops
       // the rest of the function is set to cont
       // UI not blocked
       Task.Run(async () =>
       {
            var MyValue = await doSomethingAsync();
    
        }); //there you waiting value
    
       //continue code
    }
    

提交回复
热议问题