示例总是显示如下:
private async void openBtn_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker openPicker = new FileOpenPicker();
StorageFile file = await openPicker.PickSingleFileAsync();
}
但如果用户点击两次,它将打开两个选择器窗口。这真的是正确的方式吗?
答案 0 :(得分:2)
有几个选项可以解决这个问题,首先可能是使用 Semaphore / SemaphoreSlim 并等待它。第二 - 在事件的乞讨中取消订阅,做好工作,然后订阅:
private async void openBtn_Click(object sender, RoutedEventArgs e)
{
var button = sender as Button;
button.Clik -= openBtn_Click;
FileOpenPicker openPicker = new FileOpenPicker();
StorageFile file = await openPicker.PickSingleFileAsync();
// do smth
button.Clik += openBtn_Click;