Is there a way to extend splash screen into form shown event?

前端 未结 2 810
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-07 05:58

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

相关标签:
2条回答
  • 2020-12-07 06:41

    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
    
    • Add a module to the project, typically "program"
    • Add your Sub Main
    • Go to Project Properties, uncheck use Application Framework
    • Select Sub Main in the the StartUp object drop down

    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.

    0 讨论(0)
  • 2020-12-07 06:46

    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.

    0 讨论(0)
提交回复
热议问题