У меня есть приложение C # WinForms.Это исключение выдается в методе static void Main (), когда перед запуском основной формы пользовательского интерфейса отображается DevExpress XtraMessageBox.Ниже приведен код (упрощенно):
static void Main(string[] args)
{
// Display Splash Screen.
SplashForm.Start();
if (!CheckLicense())
XtraMessageBox.Show(null, "Not Licensed!", "License Check",
MessageBoxButtons.OK, MessageBoxIcon.Information);
using (MainForm form = new MainForm())
{
SplashForm.Stop();
if (form != null)
Application.Run(form);
}
}
Несмотря на то, что это элемент управления DevExpress, при вызове к нему на самом деле выдается:Это воспроизводимо на определенной машине, но как только я добавляю MicroSoft MessageBox.Show () перед исключением для отображения отладочной информации, я больше не получаю исключение.Вот трассировка стека:
Object is currently in use elsewhere.
at System.Drawing.Graphics.get_PageUnit()
at DevExpress.Utils.Text.FontsCache.GetFontCacheByFont(Graphics graphics, Font font)
at DevExpress.Utils.Text.FontsCache.GetStringSize(Graphics graphics, String text, Font font, StringFormat stringFormat, Int32 maxWidth)
at DevExpress.Utils.Text.TextUtils.GetStringSize(Graphics g, String text, Font font, StringFormat stringFormat, Int32 maxWidth)
at DevExpress.Utils.Paint.XPaintMixed.CalcTextSize(Graphics g, String s, Font font, StringFormat strFormat, Int32 maxWidth)
at DevExpress.Utils.AppearanceObject.CalcTextSize(Graphics g, StringFormat sf, String s, Int32 width)
at DevExpress.Utils.AppearanceObject.CalcTextSize(Graphics g, String s, Int32 width)
at DevExpress.XtraEditors.Drawing.EditorButtonPainter.CalcCaptionSize(EditorButtonObjectInfoArgs e)
at DevExpress.XtraEditors.Drawing.EditorButtonPainter.CalcObjectMinBounds(ObjectInfoArgs e)
at DevExpress.XtraEditors.Drawing.SkinEditorButtonPainter.CalcObjectMinBounds(ObjectInfoArgs e)
at DevExpress.XtraEditors.ViewInfo.BaseButtonViewInfo.CalcBestFit(Graphics g)
at DevExpress.XtraEditors.BaseControl.CalcBestSize()
at DevExpress.XtraEditors.XtraMessageBoxForm.CreateButtons()
at DevExpress.XtraEditors.XtraMessageBoxForm.ShowMessageBoxDialog()
at DevExpress.XtraEditors.XtraMessageBoxForm.ShowMessageBoxDialog(XtraMessageBoxArgs message)
at DevExpress.XtraEditors.XtraMessageBox.Show(UserLookAndFeel lookAndFeel, IWin32Window owner, String text, String caption, DialogResult[] buttons, Icon icon, Int32 defaultButton, MessageBoxIcon messageBeepSound)
at DevExpress.XtraEditors.XtraMessageBox.Show(IWin32Window owner, String text, String caption, DialogResult[] buttons, Icon icon, Int32 defaultButton, MessageBoxIcon messageBeepSound)
at DevExpress.XtraEditors.XtraMessageBox.Show(IWin32Window owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
at DevExpress.XtraEditors.XtraMessageBox.Show(IWin32Window owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon)
at Test.Program.Main(String[] args)
Обновление: Я решил ее, убедившись, что Application.Run () выполняется перед выполнением любой работы пользовательского интерфейса.Таким образом, цикл сообщений / насос запускается.Теперь у меня есть Application.Run (), запускающий всплывающую форму, которая является легкой и быстрой.Затем внутри формы-заставки я создаю основную форму, активирую ее и скрываю форму-заставку.