I am trying to create a a splash screen...
I have attached the image file..please have a look..

the splash screen performs a diagnostic procedure and displayed the results in a multi-line label..

I have used another thread to write msgs as results in label..

and its working as it is supposed to work..

if it finds out that there is an error in registry or database connectivity.. it will load "frm_maintainance"..


Its almost done...
The only thing I am having trouble with is
when there is no error, i want to close the splash screen and open the "form1" which is main form.

i cant do it directly as i using second thread here..

i cant open it in the main thread and diagnostic is happening in second thread and opening "form1" in main thread will directly open the form regardless of the status of errors found.

anyone , any idea how to deal with this..?

here's my code :

Imports Microsoft.Win32
Imports System.Threading
Imports System.Data.SqlClient

Public Class frm_splash
    Dim iserror As Boolean = False

    Private Sub frm_spash_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        lbl_version.Text = Me.ProductVersion

        Dim newthread As New Thread(AddressOf check_integrity)
        newthread.Start()

    End Sub


    Private Sub check_integrity()

        Dim regkey As RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey("Software\ais", True)

        Thread.Sleep(1000)

checkintegrity:

        If regkey Is Nothing Then

            write_msg("configuration not found...!")
            write_msg("going to maintainance mode...")
            iserror = True
            GoTo skipcycle
        Else
            write_msg("done..!")
        End If

checkconfig:

        write_msg("checking application configuration..")

        If regkey.GetValueNames.Length.ToString < 9 Then
            write_msg("invalid configuration ..!")
            write_msg("going to maintainance mode...")
            iserror = True
            GoTo skipcycle
        Else
            write_msg("done..!")
        End If

checkconnection:
        write_msg("checking connection...")
        Try
            Dim constring As String = "data source =" + regkey.GetValue("sqlserverinstance").ToString + " ; user id=" + regkey.GetValue("sqlusername").ToString + " ; password=" + regkey.GetValue("sqlpassword").ToString + ";initial catalog=erp"
            Dim mycon As New SqlConnection(constring)
            mycon.Open()
            write_msg("connected..!")
            If mycon.State = ConnectionState.Open Then mycon.Close()
        Catch ex As Exception
            write_msg(ex.Message)
            write_msg("error in connectivity..!")
            write_msg("going to maintainance mode...")
            iserror = True
            GoTo skipcycle
        End Try


checkdatabase:
        write_msg("checking database...")

        Dim constring2 As String = "data source =" + regkey.GetValue("sqlserverinstance").ToString + " ; user id=" + regkey.GetValue("sqlusername").ToString + " ; password=" + regkey.GetValue("sqlpassword").ToString + ";initial catalog=erp"
        Dim mycon2 As New SqlConnection(constring2)
        mycon2.Open()
        Dim com_text As String = "if db_id('erp') is not null select 'exists' as result else select 'doesnt exist' as result"
        Dim dbchecker As New SqlCommand(com_text, mycon2)
        If dbchecker.ExecuteScalar.ToString = "exists" Then

            write_msg("database found..!")
            write_msg("loading application..")
        Else
            write_msg("database not found .!")
            write_msg("going to maintainance mode...")
            iserror = True
            GoTo skipcycle
        End If

        regkey.Close()
skipcycle:


        If iserror = True Then
            MessageBox.Show("Error starting application. " + Chr(13) + "Please configure the application appropriately", "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
            frm_maintainace.ShowDialog()
        End If


    End Sub

    Private Delegate Sub write_msg_delegate(ByVal msg As String)

    Private Sub write_msg(ByVal msg As String)

        If Me.InvokeRequired Then

            Dim delegate1 As New write_msg_delegate(AddressOf write_msg)
            Dim parameter(0) As Object
            parameter(0) = msg
            Me.Invoke(delegate1, parameter)

        Else

            Me.lbl_status.Text = Me.lbl_status.Text + Chr(13) + msg
            Thread.Sleep(500)

        End If

    End Sub
End Class
Attachments Capture.JPG 37.25 KB

You could try adding this to your splash screen's load event after newthread.Start()

Me.Close() 'Close splash screen form
If Not iserror Then form1.Show() 'Show main program form

The logic behind this is simple; if no error is found, close the splash screen and start the application. I'm not really sure it would work though because a. don't know how this is linked to the rest of your code, b. only took a quick look at your code, c. haven't worked with threads so I don't know what limitations (if any) they set, d. haven't tested. At least I hope I'm pointing you to the right direction.

that would have worked very well in a single thread application...
here, if i implement your code,

it simply will open "form1" because thread just started and value of "iserror" is still "false"..

m stuck...and its complicated..
i think i'll have to study a bit

OK, I see. I'll do a bit of research and if I come up with something useful, be sure I'll let you know. Sorry for not being able to help, by the way.

This question has already been answered. Start a new discussion instead.