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??
The answer is not to use
Thread.Sleepbut to set the MinimumSplashScreenDisplayTime (The minimum length of time, in milliseconds, for which the splash screen is displayed.)To set this:
Project>[Your project name] PropertiesApplicationtabView Application Eventsbutton next to the Splash Screen drop-downMyApplicationobject from the object selection drop down (top left menu)OnCreateSplashScreenmethod declaration from the method drop down (top right menu)OnCreateSplashScreenmethodMinimumSplashScreenDisplayTime = 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)