2016-07-05 3 views
0

MessageDialog의 ShowAsync() 메서드가 산발적으로 실패합니다.MessageDialog ShowAsync throwing accessdenied exception

private async Task CloseApp() 
{ 
    MessageDialog restartMessage = new MessageDialog("Changes have made a restart necessary.", "App must Restart") 
    restartMessage.Commands.Add(new UICommand("Close Application", (command) => { Application.Current.Exit(); })); 

    await restartMessage.ShowAsync(); // Code breaks here 
    Application.Current.Exit(); 
} 

은 내가 almost identical problem와 다른 사용자를 찾았지만, 해당 페이지의 모든 솔루션은 발생 내 오류를 방지하는 데 실패 : 그것은 같은 작동 여부에 꽤 많은 동전 던지기이다. 이들 솔루션은 다음과 같은 :

private async Task CloseApp() 
{ 
    IAsyncOperation<IUICommand> asyncCommand = null; 
    MessageDialog restartMessage = new MessageDialog("Changes have made a restart necessary.", "App must Restart") 
    restartMessage.Commands.Add(new UICommand("Close Application", (command) => { Application.Current.Exit(); })); 
    restartMessage.DefaultCommandIndex = 0; 

    asyncCommand = restartMessage.ShowAsync(); // Code *still* breaks here 
    Application.Current.Exit(); 
} 

업데이트 :

문제는 다른 MessageDialog에 의해 호출하는 방법에 MessageDialog에 ShowAsync()를 실행하려고에서 오는 될 수 있습니다. 동시에 두 개의 MessageDialog를 표시 할 수 없으므로 오류가 발생합니다. 디스패처를 사용

내 솔루션 ... 실제로 여전히 작동하지만, 어쨌든 수컷 거위가 없습니다 : 나는 문제가 MessageDialog 내에서 MessageDialog을 열 것을 알아 낸 후

MessageDialog restartMessage = new MessageDialog("Changes have made a restart necessary.", "App must Restart"); 
restartMessage.Commands.Add(new UICommand("Close Application", (command) => { Application.Current.Exit(); })); 

CoreDispatcher cD = Window.Current.CoreWindow.Dispatcher; 
await cD.RunAsync(CoreDispatcherPriority.Normal, async() => 
{ 
    await restartMessage.ShowAsync(); 
}); 
+0

: 여기에 구현 된 솔루션을 사용할 수? 나는 두 번째 것을 표시해야 하는지를 알기 위해 첫 번째 결과를 필요로한다고 생각합니다. – Vincent

+0

나는 CoreDispather가 첫 번째 메시지가 끝난 후 두 번째 메시지가 열리게한다고 생각했지만, 분명히 그렇지 않다. 레코드의 경우 첫 번째 메시지 대화 상자에서만 내 SaveDate() 메서드를 호출합니다. 이 코드 조각은 SaveData() 메서드 내부에서 호출됩니다. 뭔가 잘못되어 응용 프로그램을 닫아야하는 경우입니다. 내 restartMessage를 올리기 전에 열려있는 MessageDialogs를 강제 종료 할 수있는 방법이 있다면이 작업을 할 수 있지만 그 일을 할 수있는 방법은 모른다. –

답변

관련 문제