dipan chikani
dipan chikani

Reputation: 199

Two Form Threading in one Need:"MainForm" Load Behind "Splash Form"

Two Forms 1. "SplashForm" 2. "MainForm"

I want to load "MainForm" AS background Process of "SplashForm" process when "SplashForm" process end i just want to show the "MainForm" which should be already loaded code

VB Code:

Imports System
Imports System.Threading

Public Class MultiThreading
    ' Global declaration 
    Dim mf As New MainForm
    'Thread Declaration
    Dim tm As New Thread(AddressOf LoadProcess)
    Dim ts As New Thread(AddressOf Splashprocess)

    Private Sub Epaper_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Opacity = 0
        tm.Start()
        ts.Start()
    End Sub

    Sub  LoadProcess()
        mf.Show()
        mf.Hide()
    End Sub

    Sub Splashprocess()
        For i As Integer = 0 To 1000
            Me.Opacity += 0.01
        Next
        If Me.Opacity = 1 Then
            mf.Show()
            Me.Hide()
        End If
    End Sub
    End Class

Upvotes: 0

Views: 795

Answers (1)

Érik Desjardins
Érik Desjardins

Reputation: 993

Why don't you call the SplashScreen from the main form? Your main form should be invisible at first. When the main form is loaded, You could first of all show the splashscreen as an independant form (not child), then proceed on loading your main form. When all the process is done, dismiss the splashscreen and show the main form.

Therefore, you would avoid using homemade threads.

Here is a pseudo-code exemple :

In Main_Form class                // which is invisible
{
    When Main_Form is loaded
    {
        Show SplashScreen

        Proceed on loading everything else

        Hide SplashScreen
        Show Main_Form
    }
}

Upvotes: 1

Related Questions