调用MessageBox.Show没有来得及弹出对话框再次调用MessageBox.Show引起0x8000FFFF异常,解决方法:
private static mMsgboxShown = false;
public static MessageBoxResult ShowMessageBox(string text,stringcaption,MessageBoxButtonmsgBoxBtn)
{
MessageBoxResult ret =MessageBoxResult.None;
if (!mMsgboxShown)
{
mMsgboxShown = true;
ret = MessageBox.Show(text, caption,msgBoxBtn);
mMsgboxShown = false;
}
return ret;
}
下面是捕获到的异常:
//try
{
if (MessageBox.Show("是否退出***?\n点击确认,退出。\n点击取消,继续使用。",
"退出程序:", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
{
e.Cancel = true;
}
}
//catch (Exception err)
//{
// Message "0x8000ffff"
// StackTrace
// "at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
// at MS.Internal.XcpImports.MessageBox_ShowCore(String messageBoxText, String caption, UInt32 type)
// at System.Windows.MessageBox.ShowCore(String messageBoxText, String caption, MessageBoxButton button)
// at System.Windows.MessageBox.Show(String messageBoxText, String caption, MessageBoxButton button)
// at BaseClass.BasicPhoneApplicationPage.PhoneApplicationPageModel.PhoneApplicationPage_BackKeyPress(Object sender, CancelEventArgs e)
// at Microsoft.Phone.Controls.PhoneApplicationPage.ShellPageCallback_OnBackKeyPress(Object source, BackKeyPressEventArgs e)
// at Microsoft.Phone.Shell.Interop.ShellPageCallback.FireOnBackKeyPress(IntPtr pageThis)
// at MS.Internal.XcpImports.MessageBox_ShowCoreNative(IntPtr context, String messageBoxText, String caption, UInt32 type, Int32& result)
// at MS.Internal.XcpImports.MessageBox_ShowCore(String messageBoxText, String caption, UInt32 type)
// at System.Windows.MessageBox.ShowCore(String messageBoxText, String caption, MessageBoxButton button)
// at System.Windows.MessageBox.Show(String messageBoxText, String caption, MessageBoxButton button)
// at BaseClass.BasicPhoneApplicationPage.PhoneApplicationPageModel.PhoneApplicationPage_BackKeyPress(Object sender, CancelEventArgs e)
// at Microsoft.Phone.Controls.PhoneApplicationPage.ShellPageCallback_OnBackKeyPress(Object source, BackKeyPressEventArgs e)
// at Microsoft.Phone.Shell.Interop.ShellPageCallback.FireOnBackKeyPress(IntPtr pageThis)"
//}