I've a button in my WPF application which function as follows
private void Button_Click(object sender, RoutedEventArgs e)
{
loadingSpinner.Visibility = Visibility.Visible;
DoSomeTask(); // Takes 3-4 seconds
}
My problem is the below code
loadingSpinner.Visibility = Visibility.Visible;
executes after DoSomeTask()
execution is completed and all the UI related code is blocked which is written above it. I tried background workers, Parallel.Invoke and async Task but nothing worked. This just looked like a job of couple of minutes but it has been over a day and I'm not able to go past through it.
EDIT
If I try await like this
private async void Button_Click(object sender, RoutedEventArgs e)
{
loadingSpinner.Visibility = Visibility.Visible;
await Task.Run(() => DoSomeTask()); // Takes 3-4 seconds
}
The loadingSpinner becomes visible but code inside DoSomeTask() is never executed (which opens a webpage and performs some actions)
private void DoSomeTask()
{
//... init variables
driver.Navigate().GoToUrl("https://myurl.com");
//.. some clicks and data filling
driver.FindElement(By.Id("name")).SendKeys("Test");
driver.FindElement(By.Id("btn")).Click();
}