gpt4 book ai didi

windows - MessageDialog ShowAsync 在第二个对话框中抛出 accessdenied 异常

转载 作者:可可西里 更新时间:2023-11-01 12:12:47 25 4
gpt4 key购买 nike

我正在尝试在 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();
}
}

最佳答案

好的,我找到了一个快速的解决方案,

定义一个 IAsyncOperation 类变量

IAsyncOperation<IUICommand> asyncCommand = null;

并将其设置为MessageDialog的ShowAsync方法

asyncCommand = msg.ShowAsync();

在重试/重试的命令处理程序中检查 asyncCommand 是否不为 null 并在必要时取消最后的操作

if(asyncCommand != null)
{
asyncCommand.Cancel();
}

如果有更好的方法,请告诉我。

关于windows - MessageDialog ShowAsync 在第二个对话框中抛出 accessdenied 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12722490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com