Skindeep2366
Skindeep2366

Reputation: 1559

SplashScreen staying open even after Application Exits

Windows Forms VB Application.. I added a splashScreen to my application. And it was flashing only for a second then going away so I added a sleep timer to my Form Load event... The problem is now the splashScreen stays open even After Application exits, instead of simply closing at the end of the sleeptimer.. The Part of the Form Load event that is causing this is as follows:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load

Threading.Thread.Sleep(5000)
Me.WindowState = FormWindowState.Maximized
Dim _year As String = System.DateTime.Now.Year.ToString

I am using a stock Splashscreen that was created by going to myproject. The code for it is as follows: Public NotInheritable Class SplashScreen1

'TODO: This form can easily be set as the splash screen for the application by going to the "Application" tab
'  of the Project Designer ("Properties" under the "Project" menu).


Private Sub SplashScreen1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


    'Set up the dialog text at runtime according to the application's assembly information.  

    'TODO: Customize the application's assembly information in the "Application" pane of the project 
    '  properties dialog (under the "Project" menu).

    'Application title
    If My.Application.Info.Title <> "" Then

    Else
        'If the application title is missing, use the application name, without the extension
        'ApplicationTitle.Text = System.IO.Path.GetFileNameWithoutExtension(My.Application.Info.AssemblyName)
    End If

    'Format the version information using the text set into the Version control at design time as the
    '  formatting string.  This allows for effective localization if desired.
    '  Build and revision information could be included by using the following code and changing the 
    '  Version control's designtime text to "Version {0}.{1:00}.{2}.{3}" or something similar.  See
    '  String.Format() in Help for more information.
    '
    '    Version.Text = System.String.Format(Version.Text, My.Application.Info.Version.Major, My.Application.Info.Version.Minor, My.Application.Info.Version.Build, My.Application.Info.Version.Revision)

    Version.Text = System.String.Format(Version.Text, My.Application.Info.Version.Major, My.Application.Info.Version.Minor)

    'Copyright info
    Copyright.Text = My.Application.Info.Copyright


End Sub

End Class

There is nothing more in the function related to this at all.. The rest is used to populate the form labels and textboxes... If I delete the Threading.Thread.Sleep(5000) line the splash screen only flickers for a second but does exit after it finishes.. Any ideas??

Upvotes: 1

Views: 5808

Answers (4)

Steve Gray
Steve Gray

Reputation: 107

This was happening to me and it was caused by an error in the form OnLoad event. I cleared up the error and the splash screen started behaving normally.

BTW, I have this form set to Maximized, that setting has no effect on the splash screen

Upvotes: 0

Skindeep2366
Skindeep2366

Reputation: 1559

Thanks much for the help on that one... It is working now.. But I had to comment out

  Me.WindowState = FormWindowState.Maximized

For some reason it was breaking the minimum splash time..

Upvotes: 1

Matt Wilko
Matt Wilko

Reputation: 27322

The answer is not to use Thread.Sleep but to set the MinimumSplashScreenDisplayTime (The minimum length of time, in milliseconds, for which the splash screen is displayed.)

To set this:

  1. Select Project>[Your project name] Properties
  2. Application tab
  3. click on the View Application Events button next to the Splash Screen drop-down
  4. Select The MyApplication object from the object selection drop down (top left menu)
  5. Select the OnCreateSplashScreen method declaration from the method drop down (top right menu)
  6. Add the follwing line in the OnCreateSplashScreen method MinimumSplashScreenDisplayTime = 10000

(If you have not done so already you need to set your splash screen form to be the splash screen of your application, see how to specify the splashscreen)

Upvotes: 4

xRed
xRed

Reputation: 1997

FormName.MinimumSplashScreenDisplayTime = 10000 

It will display the splashscreen for 10 seconds.

Upvotes: 1

Related Questions