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

  • Home
  • SEARCH
  • 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 3599006
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:18:49+00:00 2026-05-18T20:18:49+00:00

Since I added a splash screen my main form will sometimes (about 1 every

  • 0

Since I added a splash screen my main form will sometimes (about 1 every 20 times) disappear like it’s minimized (it will be invisible but it will be still on the task bar and if I click it it reappears). Here is my code:

static class Program
{
    private static SplashScreen splashScreen = null;
    private static ManualResetEvent splashScreenWaiter = null;
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        ShowSplashAsync();
        BuilderForm2 builderForm2 = new BuilderForm2();
        builderForm2.Shown += new EventHandler(builderForm2_Shown);
        Application.Run(builderForm2);
    }

    private static void HideSplash()
    {
        if (splashScreenWaiter != null)
        {
            splashScreenWaiter.WaitOne();
            splashScreen.Invoke(new Action(splashScreen.Close));
            splashScreenWaiter = null;
            splashScreen = null;
        }
    }

    private static void builderForm2_Shown(object sender, EventArgs e)
    {
        HideSplash();
    }

    private static void ShowSplashAsync()
    {
        splashScreenWaiter = new ManualResetEvent(false);
        Thread splashThread = new Thread(ShowSplash);
        splashThread.IsBackground = true;
        splashThread.SetApartmentState(ApartmentState.STA);
        splashThread.Start(splashScreenWaiter);
    }

    private static void ShowSplash(object resetEvent)
    {
        splashScreen = new SplashScreen((ManualResetEvent)resetEvent);
        Application.Run(splashScreen);
    }
}

And this is SplashScreen code:

public partial class SplashScreen : Form
{
    private ManualResetEvent ResetEvent;
    bool handleCreated = false;
    bool formShown = false;

    public SplashScreen(ManualResetEvent resetEvent)
    {
        ResetEvent = resetEvent;
        HandleCreated += new EventHandler(SplashScreen_HandleCreated);
        InitializeComponent();
    }

    private void SetResetEventIfReady()
    {
        if(handleCreated && formShown) ResetEvent.Set();
    }

    private void SplashScreen_Shown(object sender, EventArgs e)
    {
       formShown = true;
       SetResetEventIfReady();
    }

    void SplashScreen_HandleCreated(object sender, EventArgs e)
    {
        handleCreated = true;
        SetResetEventIfReady();
    }
}
  • 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-18T20:18:49+00:00Added an answer on May 18, 2026 at 8:18 pm

    Nothing jumps out. There is however a very serious race condition in your code. It is related to the SystemEvents class. That class provides important notifications to controls so they can respond to the user changing the Windows theme. That class needs a hidden notification window to receive messages about the changes the user made.

    This goes very wrong if your program’s first window is created on a worker thread instead of the UI thread. That makes the SystemEvents class create that notification window on the wrong thread (not your worker thread btw). And the events it raises will be called from that thread. Getting the event on that wrong thread creates havoc, controls are not thread-safe. The most typical outcome is that you’ll have odd painting problems or the form deadlocks when you lock the workstation. I can imagine what you see going wrong could be explained by this as well.

    The .NET framework already has excellent and time-tested support for splash screens. I recommend you use it instead of spinning your own. Check this answer for the code.

    If you want to keep your own then you can work around the race problem by pasting this line of code into your Main method, before the ShowSplashAsync call:

      Microsoft.Win32.SystemEvents.UserPreferenceChanged += delegate { };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a django application, I am receiving a POST variable with a name of
I am using a Masterpage for my upload_photo.aspx which displays the file upload page
I have overwritten the tab bar controller and tab bar item classes in my
I'm trying to use git checkout <hash> <directory> to checkout a previous revision of
I am using Hibernate in Spring MVC 3.05 and an Oracle database. I have
I have been using: if ($_POST['Comments']!=){ $comments = mysql_real_escape_string($_POST['Comments']); }else{ $comments = ; }
i am getting this error Shader uses texture addressing operations in a dependency chain
I'm coding a simple bands that goes on at the bottom of the browser
I have a C# application and a C DLL both of which I wrote
I have a table with the following declarative definition: class Type(Base): __tablename__ = 'Type'

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.