asked on
<Window x:Class="WpfApp7TestAsyncUI.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp7TestAsyncUI"
mc:Ignorable="d"
Title="MainWindow" Height="250" Width="400">
<Grid>
<Button Content="Button" HorizontalAlignment="Left" Margin="160,72,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
</Grid>
</Window>
MainWindow.xaml.csusing System.Windows;
namespace WpfApp7TestAsyncUI
{
public partial class MainWindow : Window
{
private MainWindowViewModel viewModel;
public MainWindow()
{
this.viewModel = new MainWindowViewModel();
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
this.viewModel.HandleButtonClick();
}
}
}
MainWindowViewModel.csusing System.Threading.Tasks;
namespace WpfApp7TestAsyncUI
{
public class MainWindowViewModel
{
public async void HandleButtonClick()
{
await Task.Delay(100).ConfigureAwait(false);
Window1 window1 = new Window1();
}
}
}
There's also a simple Window1.xaml which is empty:<Window x:Class="WpfApp7TestAsyncUI.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp7TestAsyncUI"
mc:Ignorable="d"
Title="Window1" Height="450" Width="800">
<Grid>
</Grid>
</Window>
Window1.xaml.csusing System.Windows;
namespace WpfApp7TestAsyncUI
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
}
}
That's it. The problem is in MainWindowViewModel.Handle public async void HandleButtonClick()
{
await Task.Delay(100).ConfigureAwait(false);
Window1 window1 = new Window1();
}
Here the await Task.Delay(100).ConfigureA