我正在尝试在调度计时器中使用消息对话框来在时间完成时更改用户。但有时它会给出以下错误:“访问被拒绝。(来自 HRESULT 的异常:0x80070005(E_ACCESSDENIED))”。如何解决这个问题?
代码:
public DetailPage()
{
timer = new DispatcherTimer();
timer.Tick += dispatcherTimer_Tick;
timer.Interval = new TimeSpan(0, 0, 1);
this.txtTimer.Text = GlobalVariables.totalTime.Minutes + ":" + GlobalVariables.totalTime.Seconds + "mins";
timer.Start();
}
async void dispatcherTimer_Tick(object sender, object e)
{
if (GlobalVariables.totalTime.Minutes > 0 || GlobalVariables.totalTime.Seconds > 0)
{
GlobalVariables.totalTime = GlobalVariables.totalTime.Subtract(new TimeSpan(0, 0, 1));
this.txtTimer.Text = GlobalVariables.totalTime.Minutes + ":" + GlobalVariables.totalTime.Seconds + " mins";
}
else
{
timer.Tick -= dispatcherTimer_Tick;
timer.Stop();
MessageDialog signInDialog = new MessageDialog("Time UP.", "Session Expired");
// Add commands and set their callbacks
signInDialog.Commands.Add(new UICommand("OK", (command) =>
{
this.Frame.Navigate(typeof(HomePage), "AllGroups");
}));
// Set the command that will be invoked by default
signInDialog.DefaultCommandIndex = 1;
// Show the message dialog
await signInDialog.ShowAsync();
}
}
我在以下位置收到错误:
// Show the message dialog
await signInDialog.ShowAsync();