I am trying to close a MessageDialog in my WinRT App. I have noticed if I attempt to show two message dialogs at once, I get an UnauthorizedAccessException. To avoid this, I want to close the existing message dialog if it is open. I use this to show the dialog:
MessageDialog md = new MessageDialog(" ");
private void MessageBox(string s)
{
Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
md.Content = s;
//CLOSE HERE
md.ShowAsync();
}
);
}
How do I close it?
Right-click the icon referring to the dialog box from the Windows taskbar and click “Close”.
You can use the methods cancel() or dismiss() .
instead of trying to find a way to close it, try this declare a instance variable for AsyncCommand;
AsyncCommand command;
command = md.ShowAsync();
then in your commandhandler, before running your method check if command is null
if(command!=null)
{
command.Cancel();
}
// do stuff/ tryagain block
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With