Estoy tratando de implementar try again/cancel cuadro de diálogo en Windows 8. El cuadro de diálogo muestra bien la primera vez, pero al hacer clic en try again y fallar nuevamente, obtengo una excepción de acceso denegado al llamar a ShowAsync. No sé por qué, pero a veces es extraño, el código funciona bien y no obtengo la excepción cuando pongo puntos de corte. realmente despistado aquíMessageDialog ShowAsync arroja una excepción accessdenied en el segundo cuadro de diálogo
aquí está el código.
async void DismissedEventHandler(SplashScreen sender, object e)
{
dismissed = true;
loadFeeds();
}
private async void loadFeeds()
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
{
try
{
RSSDataSource rssDataSource = (RSSDataSource)App.Current.Resources["RSSDataSource"];
if (rssDataSource != null)
{
await rssDataSource.DownloadFeeds();
await rssDataSource.GetFeedsAsync();
}
AdDataSource ads = (AdDataSource)App.Current.Resources["AdDataSource"];
if (ads != null)
{
await ads.DownloadAds();
}
rootFrame.Navigate(typeof(HomePageView));
Window.Current.Content = rootFrame;
}
catch
{
ShowError();
}
});
}
async void ShowError()
{
// There was likely a problem initializing
MessageDialog msg = new MessageDialog(CONNECTION_ERROR_MESSAGE, CONNECTION_ERROR_TITLE);
// Add buttons and set their command handlers
msg.Commands.Add(new UICommand(COMMAND_LABEL_RETRY, new UICommandInvokedHandler(this.CommandInvokedHandler)));
msg.Commands.Add(new UICommand(COMMAND_LABEL_CLOSE, new UICommandInvokedHandler(this.CommandInvokedHandler)));
// Set the command to be invoked when a user presses 'ESC'
msg.CancelCommandIndex = 0;
await msg.ShowAsync();
}
/// <summary>
/// Callback function for the invocation of the dialog commands
/// </summary>
/// <param name="command">The command that was invoked</param>
private void CommandInvokedHandler(IUICommand command)
{
string buttonLabel = command.Label;
if (buttonLabel.Equals(COMMAND_LABEL_RETRY))
{
loadFeeds();
}
else
{
// Close app
Application.Current.Exit();
}
}
Para prevenir el "Uso de variable local no asignada 'asyncCommand'", que tuvieron que asignar null para asyncCommand cuando está asignado. –
Nota al margen: tenía mi propia tarea Que se ejecuta en un solo hilo y solo estaba haciendo ONE ShowAsync de UN hilo a la vez. Aparentemente, si una ShowAsync finaliza en la trama 1 y una segunda ShowAsync se inicia en la trama 2, puede aparecer un error aleatorio Acceso denegado: /. Sin embargo, cancela manualmente trabajos. – RelativeGames
@clay Actualicé el código anterior – Syler