.netwpfc#-4.0telerikbusyindicator

Application in hanged state on clicking the popup


I'm trying to display a popup in the bottom right corner of the screen at time of login in my program.

The page which I'm calling at the time of login has a telerik radbusyindicator. Upon logging in, the page opens and displays the busy indicator and the popup, which works fine.

But if I click on the popup while the busy indicator is working, my program gets hanged (i.e. it becomes unresponsive and i have to kill the process from the task manager).

Can anyone help me out here.

for code reference, I'm using WPF.

Thanks


Solution

  • You need to use "async" and "await" keywords in order for your UI to be responsive when executing somthing in the background. that way whatever you are executing on the backgroung will be executed on a differnt task and not freeze your UI:

     private async void LoginButtonClick(object sender, RoutedEventArgs e)
     {
         try
         {
             radbusyindicator.Visibility = Visibility.Visible;
             await LoginAsync();
             radbusyindicator.Visibility = Visibility.Hidden;
         }
         catch (Exception)
         {      
         }
     }
    
     private async Task<string> LoginAsync()
     {
        try
        {
            var loginTask = await Task.Run(() =>
            {
                 Login();
                 return "Login Successfully !"
            });
            return loginTask.Result;
        }
        catch (Exception ex)
        {
    
        }
    }