2014-10-22 3 views
1

를 사용하는 경우 내 Windows 스토어 앱에 CommandBar 있고, 내 CommandBarOpen 버튼을 클릭하면 다음과 같이, 그것은 OpenFile 핸들러를 실행 하지만 내가 Yes을 누르는 경우에만 FileOpenPicker이 표시됩니다. No을 클릭하면UnauthorizedAccessException FileOpenPicker

나는이 일이 왜 일어나는 지 알고 있습니다. 심지어 불행하게도 ... 핸들러가 다른 스레드에서 호출되고 있다는 오프 기회에 디스패처에서 실행하지만, 시도, 같은 일 :

await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High, async() => 
{ 
    StorageFile file = await fileOpenPicker.PickSingleFileAsync(); 
    await LoadFile(file); 
}); 
+0

인해 이미 다른이 생각하는 바보 RT 경주 조건 :이 솔루션은 MessageBox.ShowWinForms에서 같은 방법으로 당신이 사용하는 것과 MessageDialog 클래스의 그대로 메이크업 사용에 나를 위해이었다 대화 상자는 현재 존재하지 않더라도 (존재하지 않더라도) 이전 (프롬프트 중 하나)이 닫힐 때까지 새 파일 (파일 선택기)을 시작하지 않으며 여기에있는 기술 중 일부를 시도하고 솔루션을 다시 게시합니다. http :// /stackoverflow.com/questions/12722490/messagedialog-showasync-throws-accessdenied-exception-on-second-dialog – Alexandru

답변

0

은 예, RT의 대화 경쟁 조건에 기인 . 나는이있을 수 있습니다 생각

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?"); 
    IUICommand result = null; 
    dialog.Commands.Add(new UICommand("Yes", (x) => 
    { 
     result = x; 
    })); 
    dialog.Commands.Add(new UICommand("No", (x) => 
    { 
     result = x; 
    })); 
    await dialog.ShowAsync(); 
    if (result.Label == "Yes") 
    { 
     await SaveFile(); 
    } 
    FileOpenPicker fileOpenPicker = new FileOpenPicker(); 
    fileOpenPicker.ViewMode = PickerViewMode.List; 
    fileOpenPicker.FileTypeFilter.Add(".txt"); 
    StorageFile file = await fileOpenPicker.PickSingleFileAsync(); 
    await LoadFile(file); 
} 
관련 문제