In below WPF code, there is only a button and a label. I expected the behaviour to be like this: I will see button is disabled and "Doing Stuff" is written on the label and THEN UI will be frozen. But this is not the case. I do not even see "Doing Stuff" label UI is frozen till the beginning. Can you tell me the logic behind this? Why Thread.Sleep makes the UI instantly freeze?
using System.Threading.Tasks;
using System.Threading;
using System.Windows;
namespace MessagePump
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void btnDoStuff_Click(object sender, RoutedEventArgs e)
{
btnDoStuff.IsEnabled = false;
lblStatus.Content = "Doing Stuff";
Thread.Sleep(4000);
lblStatus.Content = "Not doing anything";
btnDoStuff.IsEnabled = true;
}
}
}
;