How can I close a splash screen during the main form's Load event?

I have an application that performs a series of tests during the main form Load event. I want to display error messages when a test fails, but the problem I am having is that the splash screen is rendered on top of the message box, and I cant close the splash screen because I dont have access to the splash screen object (I think windows creates it in a different threat).
Is there anything I can do to allow me to close the splash screen before the main form is finished loading? Alternativaly, is there anything I can do to render messageboxes on top of the splash screen?
aferiaAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
*I'm running VS2010 so there are slight differences...

Try this instead:
Public Class FSplashScreen

    Public Delegate Sub CloseDelegate()

    Public Sub CloseIt()
        Me.Invoke(New CloseDelegate(AddressOf CloseSplash), New Object() {})
    End Sub

    Private Sub CloseSplash()
        Me.Close()
    End Sub

End Class

Open in new window

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
What version VB.net and how are you displaying the splash screen?
0
 
ZhaolaiCommented:
Search your code for frmSplash.Show or whatever the splash form's name is. It's either in your main form's Load event or sub Main(). Before the messagebox opens up, do a close on the splash screen.

        SplashScreen1.Show()
        ' testing code here
         SplashScreen1.Close()
         MessageBox.Show("message here")
 

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
aferiaAuthor Commented:
I am running VS 2005 and I have added the splash screen by selecting a form  through the properties window for the project.
Thanks.
0
 
ZhaolaiCommented:
Then the splash form must have a name. You must have code to show the splash form,  Then you can close it at will.
 
0
 
aferiaAuthor Commented:
I would like to keep the initialization code in the Main Form's Load event as I have a few member variables in Main that are used by the tests.
0
 
aferiaAuthor Commented:
The splash screen has a name 'FSplashScreen', but if I try to close it from the Main's Load II get an error message because the splash screen object is declared in a different thread, so I cant have access to it.

0
 
ZhaolaiCommented:
Maybe you don't need another thread for splash screen. Can it be in the same thread as the main form?
0
 
aferiaAuthor Commented:
This is the behavior implemented by VS 2005, I have no control over it. It works well because it shows the splash screen before anything from my main form is loaded. Otherwise it would have a delay even if I showed it on the first line of code in Main's load.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Zhaolia...he said:

    "I have added the splash screen by selecting a form  through the properties window for the project."

So the Framework is displaying the splash screen by itself and managing the thread...

Attached is an image of what it would look like in Project --> Properties.

Below is one way to make the splash screen close itself from the main form:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Debug.Print("First Sleep")
        System.Threading.Thread.Sleep(3000)

        Debug.Print("Closing Splash Form...")

        FSplashScreen.CloseIt()

        Debug.Print("Second Sleep")
        System.Threading.Thread.Sleep(3000)
    End Sub

End Class

Public Class FSplashScreen

    Public Sub CloseIt()
        Me.Invoke(New Action(AddressOf CloseSplash))
    End Sub

    Private Sub CloseSplash()
        Me.Close()
    End Sub

End Class

Open in new window

SplashScreenSetting.jpg
0
 
aferiaAuthor Commented:
The line: Me.Invoke(New Action(AddressOf CloseSplash)) is causing the following compile error:
Too few type arguments to 'System.Action(Of T)'
0
 
ZhaolaiCommented:
@Idle_Mind, thanks. Learn something today.
0
 
aferiaAuthor Commented:
Awesome! This bug in my software had been lingering around for a long time! This got me interested in learning more about the Invoke method, I had never heard of it before. Thanks a lot for the help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.