In my wpf application I know I should update UI elements on the main thread. What I do is I use the main window dispatcher in order to do so. I am just curios to see why this code does not work:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Loaded += MainWindow_Loaded;
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
Task.Factory.StartNew(() =>
{
Console.Write("test");
Task.Factory.StartNew(() =>
{
// why does this code does not execute!! ???
Thread.Sleep(1000);
txt.Text = "Testing";
}, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
});
}
}
why does the inner task does not execute? In other words my program never reaches the line Thread.Sleep(1000);
Why is this?