0
votes

I have a Windows forms project, written in vb.net 2005.

It's all working fine, except that the Splash screen won't show before the frmMain is shown.

In Project properties I have set the Splash screen. In the Splash screen Shown event I have set a delay using System.Threading.Thread.Sleep(3000)

But the main MDI form just loads, and then the Splash screen is obviously behind it as the cursor is showing 'Wait' for a few seconds.

In VS 2005 it used to work beautifully, show the Splash screen for a couple of seconds, then load the main form.

Is there something else I need to do in VS 2008?

thanks

1
Using Thread.Sleep() on a thread that displays UI is a very good way to cause random trouble like this. Windows gets pretty sulky when a window stops responding to messages. Increase the MinimumSplashScreenDisplayTime property value instead.Hans Passant
@HansPassant, thanks - where is that setting please? I don't see it in Project or frmSplash properties.Our Man in Bananas

1 Answers

1
votes

Click on Project --> Properties --> Application Tab --> (Scroll Down to Bottom Right) --> "View Application Events" Button, and you should see something like:

Namespace My

    ' The following events are available for MyApplication:
    ' 
    ' Startup: Raised when the application starts, before the startup form is created.
    ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
    ' UnhandledException: Raised if the application encounters an unhandled exception.
    ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
    ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
    Partial Friend Class MyApplication

    End Class

End Namespace

Now override OnInitialize() and set MinimumSplashScreenDisplayTime() as outlined here:

Namespace My

    ' The following events are available for MyApplication:
    ' 
    ' Startup: Raised when the application starts, before the startup form is created.
    ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
    ' UnhandledException: Raised if the application encounters an unhandled exception.
    ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
    ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
    Partial Friend Class MyApplication

        Protected Overrides Function OnInitialize(ByVal commandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String)) As Boolean
            ' Set the display time to 3000 milliseconds (3 seconds):
            Me.MinimumSplashScreenDisplayTime = 3000
            Return MyBase.OnInitialize(commandLineArgs)
        End Function

    End Class

End Namespace