当用户点击右上角的X关闭应用程序时,为什么我的UWP应用程序退出调试模式?
当控件上没有异步事件时,它会正常退出,但是一旦我将按钮的click事件更改为异步(FilePicker需要这个),应用程序就不会退出调试模式。< / p>
似乎有东西在某事上有参考,但我该如何调试呢?为什么只有在存在异步操作时才会发生这种情况?
代码:
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private async void OnButtonPickSingleFileAsyncClicked(object sender, RoutedEventArgs e)
{
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.List;
picker.FileTypeFilter.Add("*");
picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.ComputerFolder;
var pickedFile = await picker.PickSingleFileAsync();
if (pickedFile != null)
{
filePath.Text = pickedFile.Path;
}
}
}
XAML:
<Page
x:Class="TestRepro.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestRepro"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button Content="Pick File Async" HorizontalAlignment="Center" VerticalAlignment="Center" Click="OnButtonPickSingleFileAsyncClicked"/>
<TextBlock Name="filePath" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="1"/>
</Grid>
</Page>