Link to home
Start Free TrialLog in
Avatar of emi_sastra
emi_sastra

asked on

Background process at splash screen

Hi All,

I want to show splash screen at application startup.

At the splash screen I want to do some background processing while progress bar is on progress.

 Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

        ProgressBar1.Value += 2

        If ProgressBar1.Value = 100 Then
            Timer1.Dispose()
            Me.Visible = False
            Me.Close()
        End If

    End Sub

How could i do it ?

Thank you.
Avatar of Chinmay Patel
Chinmay Patel
Flag of India image

Hi Emi,

I just found an article explaining how you can do it in VB.Net: https://social.msdn.microsoft.com/Forums/vstudio/en-US/87fb3154-21ef-4978-a40e-ec7f4ff1396e/vb-update-progressbar-on-splashscreen

From the above link,

a.      New a window form project

b.      Add a new item, a splash screen item

c.       Draw a progress bar on the splash screen

d.      Add code snippet #1 in the SplashScreen1.vb file

e.      Set splash screen for form1

f.        Add code snippet #2 in the form1.vb file

'code snippet #1

Public Delegate Sub SetProgressBarDelegate(ByVal max As Integer)
  Public Delegate Sub UpdateProgressBarDelegate(ByVal value As Integer)

  Public Sub BarLong(ByVal MemCount As Integer)
    If Me.InvokeRequired Then
      Me.Invoke(New SetProgressBarDelegate(AddressOf BarLong), MemCount)
    Else
      Me.ProgressBar1.Maximum = MemCount
    End If
  End Sub

'code snippet #2
  Public Sub ShowBar(ByVal SoFar As Integer)
    If Me.InvokeRequired Then
      Me.Invoke(New UpdateProgressBarDelegate(AddressOf ShowBar), SoFar)
    Else
      Me.ProgressBar1.Value = SoFar
    End If
  End Sub



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    SplashScreen1.BarLong(100)
    Dim i As Integer = 0
    While i <= 100
      SplashScreen1.ShowBar(i)
      i += 1
      Threading.Thread.Sleep(100)
    End While

  End Sub

Let me know how it goes.

Regards,
Chinmay.
Avatar of emi_sastra
emi_sastra

ASKER

Hi Chinmay,

Where to put background process, such as set global variable and etc ?

Thank you.
Global Variables should be put in the form1.vb.
- Global Variables should be put in the form1.vb.
I didn't mean just variable, but the background process of complex stuff such as query data etc.
Where to put the process function/sub ?

Thank you.
Is this app being deveoped for your personal use? or you are trying to learn how to build software? or this is work related where your app is going to be used by people for their work?
I am assuming the last option, for example, the foundation of the query mechanism should be in your Data Access Layer. The call to the query can be initiated from the splash screen but then would you need that data in Form1? or in any other form of your app throughout the session? If yes, then query the data using Form1 and keep the data maintained in Form1 itself so that you can use it even after you have closed the splash screen.
Here is the complete solution referenced
The big thing to note is in the projects properties set the splash screen, and when you add the item to the project you make it a splashscreen and not a module

2018-06-12_4-05-35.mp4
Hi Chinmay,

My question is simple, suppose I have a function to do setup along with progress bar. Means, the function should be finished when progress bar is finished or before it.
So, where to put the function ? Let's say the function name is "Long_Process()"

Thank you.
Hi David,

http://https//1drv.ms/u/s!AraFMFeqNr_Bhr0X3vFFX5uq_bGuhQ, i get 404 not found.
I am sorry, I still not get it.

Thank you.
Hi All,

Based on my code below, where to put a long process function ?

 Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

        ProgressBar1.Value += 2

        If ProgressBar1.Value = 100 Then
            Timer1.Dispose()
            Me.Visible = False
            Me.Close()
        End If

    End Sub

What code should I add here beside the process function?

Thank you.
Could you describe what is your long process? In this long process, do you track the progress(percentage complete, number of records loaded, tasks complete) etc? If yes, then your Time1_Tick should check that value and then calculate percent completion approximately. If you are not then I suggest you show an indefinite progress bar and just dispose the splash screen when your main form has completed everything it needs to do during the startup.
Hi Chinmay,

Let's make it simple, no need to calculate percentage of the long process.
Just need background process while showing splash screen.

Thank you.
Hi David,

I have load your project. But I don't know what is the code doing.
The splash screen just show some label and progress label.

Where to put a process function ?

Thank you.
inside of splashscreen1.vb

change this
While i <= 100
            SplashScreen1.ShowBar(i)
            i += 1
            Threading.Thread.Sleep(1000)
        End While

Open in new window

to your background startup processes
Hi David,

I know the code already.

What I want to achieve is where to put my long process code as back ground process ?
For example my function/sub name called "Long_Process", it is retrieving data and set to global variable, and create some tables.

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi David,

I will use background worker instead.

Thank you very much for your help.