У меня есть CommandBar
в мое приложение Windows Store, и при нажатии на кнопку Open
на моем CommandBar
, он запускает OpenFile
обработчик следующим образом:UnauthorizedAccessException при использовании FileOpenPicker
private async void OpenFile(object sender, RoutedEventArgs e)
{
MessageDialog dialog = new MessageDialog("You are about to open a new file. Do you want to save your work first?");
dialog.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(SaveAndOpen)));
dialog.Commands.Add(new UICommand("No", new UICommandInvokedHandler(Open)));
await dialog.ShowAsync();
}
private async void SaveAndOpen(IUICommand command)
{
await SaveFile();
Open(command);
}
private async void Open(IUICommand command)
{
FileOpenPicker fileOpenPicker = new FileOpenPicker();
fileOpenPicker.ViewMode = PickerViewMode.List;
fileOpenPicker.FileTypeFilter.Add(".txt");
StorageFile file = await fileOpenPicker.PickSingleFileAsync();
await LoadFile(file);
}
я вижу сообщение просто отлично, но только когда я ударил Yes
, я получаю представленный FileOpenPicker
. Когда я ударил No
, я получил UnauthorizedAccessException: Access is denied.
по следующей строке: StorageFile file = await fileOpenPicker.PickSingleFileAsync();
Я сбитый с толку ... Кто-нибудь знает, почему это происходит? Я даже попытался запустить его в диспетчеру на авось, что обработчик был будет вызван в другом потоке, но ... к сожалению, то же самое:
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High, async() =>
{
StorageFile file = await fileOpenPicker.PickSingleFileAsync();
await LoadFile(file);
});
Я думаю, что это может быть из-за тупое состояние гонки RT, где он думает, что там уже другое (хотя это не так) и не будет запускать новый (сборщик файлов) до тех пор, пока старый (приглашенный) не будет уволен, и попробуем некоторые из методов здесь и опубликуем решение: http://stackoverflow.com/questions/12722490/messagedialog-showasync-throws-accessdenied-exception-on-second-dialog – Alexandru