0

Recently I modified an application adding a splash screen. I decided to use WindowsFormsApplicationBase so I put all the heavy initialization logic inside

protected override void OnCreateMainForm()

On some computers all successive executions of the application after the first one cause the splash screen to be visible forever and main form is not displayed. I searched on internet to find a solution but it seems that after some bug fixes WindowsFormsApplicationBase is currently well trusted. So I did the educated guess that the race condition which causes my splash to remain on screen is related to something specific of my application. During initialization I write some progress signs on the splash with the following method:

public void showCurrentLoadStep(string message)
    {
        if (this.mySplash.IsHandleCreated)
        {
            this.mySplash.Invoke(new EventHandler(delegate
            {
                mySplash.label1.Text = message;
            }));
        }
    }

but I think this is ok.

Besides the last operation done in the MainForm constructor is

timer1.Enabled = true;

I verified that the timer callback is executed also when the splash remains and MainForm is not displayed.

What I'm going to try is to move timer1.Enabled = true; after the creation of MainForm but I would like to understand what goes wrong because, as I have already said, this race condition happens only on some computers so if I don't see it any more I cannot say I have solved it.

Update: I'm using .net framework 4.0 extended

Cœur
  • 37,241
  • 25
  • 195
  • 267
Filippo
  • 1,123
  • 1
  • 11
  • 28

1 Answers1

0

Why are you so sure that this is a race condition? You need to supply much more code in order for someone not familiar with your application to be able to help you. When are the procedures called, when is the splash dialog initialized, is it from the main form etc.

o_weisman
  • 804
  • 7
  • 19
  • ASFAIK there is only one way to use **WindowsFormsApplicationBase**, the one you can find here: [link](http://stackoverflow.com/questions/12624612/is-there-a-better-way-to-implement-a-time-consuming-splash-screen-loader). I did an educated guess about the race condition because the problem happens on only some computers (with the same .net framework version) and only at the following execution after the first one. – Filippo Oct 24 '13 at 10:03
  • @Filippo What do you mean by following execution after the first one? Do you mean, that you close the application and then run it again, or that you start another instance of the application? Notice that the Visual Basic Application Model is meant for single instance applications as stated here: http://msdn.microsoft.com/en-us/library/w3xx6ewx(v=vs.100).aspx – o_weisman Oct 24 '13 at 11:05
  • I mean closing the application and launch it again. It was observed that the first execution after a computer restart is almost always successful. After closing and starting it again on some computers it is impossible to get rid of the splash screen till a new computer restart. Disconnecting the user has proven to be insufficient. – Filippo Oct 28 '13 at 07:35
  • [link](http://stackoverflow.com/questions/392864/splash-screen-waiting-until-thread-finishes) – Filippo Oct 31 '13 at 07:57
  • In my first comment I inserted a wrong link, here is the correct one [link](http://stackoverflow.com/questions/392864/splash-screen-waiting-until-thread-finishes). I followed the **most rated answer** for implementing my splash screen. – Filippo Oct 31 '13 at 07:57