0

I'm trying to call a MessageDialog out of a PropertyChanged Handler. The first call is always successful, but when the Dialog gets called a second time, I get an UnauthorizedAccessException.

I've tried to wrap the call in a Dispatcher, but I got the same behavior.

Here's the code (snippet of MainPage.xaml.cs):

void PropertyChanged(object sender, PropertyChangedEventArgs e)
{
  await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
  {
    showMessage("Message", "Title");
  });
}

async void showMessage(String message, String title)
{
  MessageDialog dialog = new MessageDialog(message, title);
  await dialog.ShowAsync();
}

Could anybody please help me with this issue?

andr
  • 15,970
  • 10
  • 45
  • 59
  • This looks the same as http://stackoverflow.com/questions/12722490/messagedialog-showasync-throws-accessdenied-exception-on-second-dialog – Nicholas W Mar 06 '13 at 16:26

1 Answers1

1

I think your problem is that multiple property changes will cause multiple calls to display the dialog. You should only ever display one dialog at a time:

bool _isShown = false;
async void showMessage(String message, String title)
{
    if (_isShown == false)
    {
        _isShown = true;

        MessageDialog dialog = new MessageDialog(message, title);
        await dialog.ShowAsync();

        _isShown = false;
    }
}
chue x
  • 18,573
  • 7
  • 56
  • 70
  • Thanks for the answer, with the flag it works. I had also the Problem that i got two PropertyChanged Listeners on the same object and so the dialog was fired twice at the second try. – Datenmessy Mar 07 '13 at 07:48