Samuel Nicholson
Samuel Nicholson

Reputation: 3629

.NET Threading in splash screen

I'm currently trying to work on a splash screen and I have taken to use Threads, - my question is I'd like to run some code to show and close some forms once the threads are complete.

I tried adding an if statement for thread.IsAlive = False Then - But that did nothing when I tried to run it.

This is my splash class.

Public NotInheritable Class splash

    Dim sqlConnectionThread As New Thread(AddressOf mysql.connectionTest)
    Dim updateCheckThread As New Thread(AddressOf updates.updateCheck)

    Private Sub splash_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        updateCheckThread.Start()
        sqlConnectionThread.Start()
    End Sub

End Class

I'm then trying to add login.show and me.hide but obviously I need to wait until the threads have finished.

What part of threading do I need to be looking at?

Upvotes: 0

Views: 300

Answers (1)

Sam Makin
Sam Makin

Reputation: 1556

You can raise an event in your parent class, from the thread, once its (near) complete. The event will be running in the same thread as the splash, so make it update a variable and periodically check it, so you know when it is complete.

A more in depth answer can be found here: how to know when a work in a thread is complete?

Upvotes: 1

Related Questions