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 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

Since I added a splash screen my main form will sometimes (about 1 every
Here is the snapshot of the query that doesn't work since I added the
Since Rails is not multithreaded (yet), it seems like a threaded web framework would
Ever since I added this async request, I'm getting an xcode error of Sending
Ever since I added a new Class to my Android app (specifically, a sqlite
I have a huge amount of elements in my website... And since I added
Since I added some scrollTop -animation, some parts of my callback get called twice:
Im awful at multithreadding but ever since I added the following line to my
I'm having trouble finding why I never get to viewDidLoad since I added my
Since I started studying object-oriented programming, I frequently read articles/blogs saying functions are better,

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.