Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 904547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:04:13+00:00 2026-05-15T16:04:13+00:00

I have a C# WinForms application. This exception is thrown within the static void

  • 0

I have a C# WinForms application. This exception is thrown within the static void Main() method when a DevExpress XtraMessageBox is displayed prior to starting up the main UI form. Below is the code (simplified):

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);
    }
}

While it is a DevExpress control, the exception is actually thrown on the call to:

System.Drawing.Graphics.get_PageUnit()

The exception is not thrown consistently. It is reproducable on a particular machine, but once I add a MicroSoft MessageBox.Show() ahead of the exception to display debug information, then I no longer get the exception. Here is the stack trace:

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)

Update:
I resolved it by making sure Application.Run() is executed before doing any UI work. In this way the message loop/pump is started up. I now have Application.Run() starting up the splash form, which is lightweight and quick. From within the splash form I then instantiate the main form, activate it and hide the splash form.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:04:13+00:00Added an answer on May 15, 2026 at 4:04 pm

    As far as I understand, the Application.Run() needs to be specifically called before you show any form, since it starts up the window message loop/pump and basically spawns a separate thread for the UI.

    If you don’t do that, the form will not be able to process messages or paint.

    My suggestion is, load up the main form and have the main form call the splash screen before it does any of its normal FormLoad stuff. If the licensing fails, you can call Application.Exit() and return out of FormLoad, thus shutting down your app before the user can use it.

    Edit: Note that the main form will not show until after FormLoad exits, so you don’t have to worry about hiding your main form while the splash screen is showing.

    Edit 2: I found something worthwhile, using ApplicationContext. You can switch out which form is in the main context, so you can load up your splash screen in an initial application context, and then swap it out once it’s loaded. Try this:

    public class MyApplicationContext : ApplicationContext {
        SplashForm splashForm;
        MainForm mainForm;
    
        public MyApplicationContext() {
            splashForm = new SplashForm();
            base.MainForm = splashForm;
    
        }
    
        public void RunApplication() {
            // This will show the splash screen
            ThreadPool.QueueUserWorkItem(new WaitCallback(MessageLoopThread));
    
            // This will perform any miscellaneous loading functions
            splashForm.PerformLoadingFunctions();
    
            if (!CheckLicensing()) {
                ShowErrorMessage();
                Application.Exit();
                return;
            }
    
            // Now load the main form
            mainForm = new MainForm();
    
            // We're done loading!  Swap out our objects
            base.MainForm = mainForm;
    
            // Close our splash screen
            splashForm.Close();
            splashForm.Dispose();
            splashForm = null;
        }
    
        private void MessageLoopThread(object o) {
            Application.Run(this);
        }
    }
    

    Then you can call it in your main:

    static void Main() {
        MyApplicationContext applicationContext = new MyApplicationContext();
        applicationContext.RunApplication();
    }
    

    I haven’t tested this, but in theory it should work.

    Edit 3: I realized there might be some thread safety issues here that you may have to work around as well. Check out the CodeProject article. It does it better than what I did here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 526k
  • Answers 526k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer .. in PHP we use regular Expressions with preg_replace. Here… May 16, 2026 at 10:27 pm
  • Editorial Team
    Editorial Team added an answer As it turns out, the issue was impersonation account configuration.… May 16, 2026 at 10:27 pm
  • Editorial Team
    Editorial Team added an answer You need to store the token and the key provided… May 16, 2026 at 10:27 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a winforms application.Winforms start with Program.cs where we have main() defined.I have
I have written a WinForms program in C#.Net to click a button programmatically within
I have a mixed Winform/WPF application which frequently throws the exception: Could not load
I'm using VS 2005 in a VB.Net WinForms application. I have a custom User
I have a WSE 3.0 based web service, and a WinForms client application that
I have a winforms application that the users must be able to change the
I have a winforms application. I have a textbox on one form (call F1)
I have a C# WinForms application that has a WebBrowser control inside of it.
On a WinForms application that I am writing in C#, I have a DataGridViewTextBoxColumn
I have a setup project whose primary output is from a Winforms based application.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.