I recently was dealing with this error: BeginInvokeStackflowError
I am using threading,and according to my research it is because within the threading .start() event
Your app can be started other than the default "MainForm" method provided by the VB Application Framework
. This will use a Sub Main
as the starting point allowing you to control what forms show and when, and what happens before that:
' IF your form is declared here, it will be
' available to everything. e.g.:
' Friend mainfrm As Form1
Public Sub Main()
' this must be done before any forms/controls are referenced
Application.EnableVisualStyles()
' the main form for the app
' just "mainfrm = New Form1" if declared above
Dim mainfrm As New Form1
' eye candy for the user
Dim splash As New SplashScreen1
splash.Show()
' your code here to do stuff.
' you can also invoke your procedures on the main form
' mainfrm.FirstTimeSetup()
' for demo purposes
System.Threading.Thread.Sleep(2500)
' close/hide the splash once you are done
splash.Close()
' see note
' start the app with the main form
Application.Run(mainfrm)
End Sub
If you declare the splash screen as Friend at the top, you can truly extend it until all the form's load event is complete and close it there/then.
There is no way to extend the splash screen if you've implemented it using the project settings, however you can use the splash screen form as the initial form instead of your main form. As for waiting until the thread has finished to show the form (or hide the splash screen) consider using a public Boolean in the main form and change it to True once the thread has completed. You can use a timer on the splash screen to check for this Boolean change and then change the form's opacity back to 1.