我想实现重试/取消Windows 8的对话框该对话框显示精细的第一次,但在点击再试一次又一次失败,我得到一个拒绝访问的调用ShowAsync例外。 我不知道为什么,但它有时奇怪的代码工作正常,当我把断点我不明白的例外。 真的在这里独领风骚
这里是代码。
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();
}
}