How do I set up multi-threading progress bars in my application?

I have tried and research and tried and researched and am now just confused.  I need progress bars for all the action I have going on in my application.  I set up a regular one, and it showed up at the end and then I got into a danger-loop!  Please help!!  I'll even send cookies!!

By the way, I don't want start, pause, reset or any other button.  This application opens and installs begin.  That's it...

Here is my code:

Imports System.IO
Imports Microsoft.VisualBasic.FileIO
Imports System.Object
Imports Microsoft.VisualBasic.Devices.Network
Imports System.Threading
Imports System.Net
Imports System.Text.RegularExpressions


Public Class Form1
    Dim user As String = CStr(Environ("username"))
    Public isitLoad As Boolean = False
    Public fileLocation As String = ""
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        If My.Computer.FileSystem.DirectoryExists("C:\Program Files\Microsoft SQL Server\MSSQL11.DTH2012") Then
         
            System.Diagnostics.Process.Start("http://desktophousewife.com/desktopHousewife.application")
            Me.Close()

        Else
            Try

                '===========INSTALL SQL SERVER AND/OR HOME MANAGEMENT SYSTEM =========================
                installSQL()

            Catch ex As Exception
                MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End If
    End Sub
    Private Sub installSQL()

        If My.Computer.FileSystem.FileExists("C:\DTHSQL2012\ExtractFile\setup.exe") = True Then

            'check to see if it has been installed
            If My.Computer.FileSystem.DirectoryExists("C:\Program Files\Microsoft SQL Server\MSSQL11.DTH2012") = True Then

                '====== download home management system  ============================
                System.Diagnostics.Process.Start("http://desktophousewife.com/desktopHousewife.application")

            Else

                '=======install SQL for desktop housewife applications ===========================

                '====================================== NEED A PROGRESS BAR HERE FOR THE SQL INSTALL ================================
                Dim processObj As Process = Process.Start("C:\DTHSQL2012\ExtractFile\setup.exe", "/q /Action=Install /IACCEPTSQLSERVERLICENSETERMS /Hideconsole /Features=SQLEngine /InstanceName=DTH2012 /SQLSYSADMINACCOUNTS=""NT AUTHORITY\SYSTEM"" /SQLSVCACCOUNT=""NT AUTHORITY\SYSTEM"" /BROWSERSVCSTARTUPTYPE=""Automatic""")
                '==========================================================================================

                If processObj.ExitCode = 0 Then


                    '====================================== NEED A PROGRESS BAR HERE FOR THE Home Management INSTALL ================================
                    ProgressBar1.Value = 0
                    ProgressBar1.Visible = True
                    System.Diagnostics.Process.Start("http://desktophousewife.com/desktopHousewife.application")

                Else

                    '==========send error file ============================

                    MsgBox("SQL 2012 Install Failed. . . Code: " & processObj.ExitCode.ToString & ".  Please forward the email to me.")
                    Dim mMessage As String = "SQL 2012 Install Failed. . . Code: " & processObj.ExitCode.ToString
                    System.Diagnostics.Process.Start("mailto:karen@desktophousewife.com&subject=Desktop Housewife&body= " & mMessage)
                End If
            End If

        Else

            '=================START THE FULL DOWNLOAD SQL EXPRESS AND HOME MANAGEMENT SYSTEM  =============================

            My.Computer.FileSystem.CreateDirectory("C:\DTHSQL2012")

            '====================================== NEED A PROGRESS BAR HERE FOR THE download of SQL from my website ================================
            Label1.Text = "Downloading SQL Express to your harddrive."
            My.Computer.Network.DownloadFile("http://desktophousewife.com/SQLEXPR_x64_ENU.exe", "C:\DTHSQL2012\SQLEXPR_x64_ENU.exe", "", "", True, 500, True)


            '=========EXTRACT THE FILES - NEED PROGRESS BAR =======================================

            Dim temppath As String = ControlChars.Quote & Path.Combine(Application.StartupPath, "C:\DTHSQL2012\SQLEXPR_x64_ENU.exe") & ControlChars.Quote
            Dim processObj As Process = Process.Start(temppath, " /Q /X:C:\DTHSQL2012\ExtractFile")

            '============INSTALL SQL - NEED PROGRESS BAR ===============================================
            processObj = Process.Start("C:\DTHSQL2012\ExtractFile\setup.exe", "/q /Action=Install /IACCEPTSQLSERVERLICENSETERMS /Hideconsole /Features=SQLEngine /InstanceName=DTH2012 /SQLSYSADMINACCOUNTS=""NT AUTHORITY\SYSTEM"" /SQLSVCACCOUNT=""NT AUTHORITY\SYSTEM"" /BROWSERSVCSTARTUPTYPE=""Automatic""")
            Me.Label1.Text = ("Please wait while installing SQL 2012...")

            If processObj.ExitCode = 0 Then

                Label1.Text = "SQL 2012 Successfully Installed!"
                '=======start download of home management system ===============================
                System.Diagnostics.Process.Start("http://desktophousewife.com/desktopHousewife.application")

            Else

                Label1.Text = "SQL 2012 Install Failed. . . Code: " & processObj.ExitCode.ToString
                Dim mMessage As String = "SQL 2012 Install Failed. . . Code: " & processObj.ExitCode.ToString
                System.Diagnostics.Process.Start("mailto:karen@desktophousewife.com&subject=Desktop Housewife&body= " & mMessage)
            End If

        End If

    End Sub

End Class
Karen WilsonProgrammerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
You need to get that code out of the Load() event of the Form, and into the DoWork() handler of a BackgroundWorker() control.

Take a look at the example on MSDN to get an idea of how to do it...
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker(v=vs.110).aspx

Also, instead of starting things from Load(), start the BackgroudWorker() from the Shown() event of the Form.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Karen WilsonProgrammerAuthor Commented:
I do not have my install information correct, as it runs 10 times....  Thanks goodness because this morning's loop never ended.  

Here is the code:


    ' This event handler is where the time-consuming work is done.
    Private Sub backgroundWorker1_DoWork(ByVal sender As System.Object, _
    ByVal e As DoWorkEventArgs) Handles backgroundWorker1.DoWork
        Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
        Dim i As Integer

        For i = 1 To 10
            If (worker.CancellationPending = True) Then
                e.Cancel = True
                Exit For
            Else
                ' Perform a time consuming operation and report progress.
                System.Threading.Thread.Sleep(500)
                worker.ReportProgress(i * 10)

                '============================ what I inserted ==================================================================
                '================================================================================================================

                If My.Computer.FileSystem.DirectoryExists("C:\Program Files\Microsoft SQL Server\MSSQL11.DTH2012") Then

                    '=====THIS RUNS 10 TIMES WHICH IS THE INCREMENTS FROM ABOVE FOR I = 1 TO 10 ======================

                    System.Diagnostics.Process.Start("http://desktophousewife.com/desktopHousewife.application")
                Else
                    Try
                        '===========INSTALL SQL SERVER AND/OR HOME MANAGEMENT SYSTEM =========================
                        installSQL()

                    Catch ex As Exception
                        MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
                    End Try
                End If
                '===================================================================================================================
                '===================================================================================================================
            End If
        Next
    End Sub

Also, is this correct:


    Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        BackgroundWorker1.RunWorkerAsync()
    End Sub

Thanks!
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
The loop in the example was simply there so that it would have "steps" and it could report something.

You DO NOT need that loop in YOUR code!

Instead, after each step in your process, you'd manually report back the percentage complete.

Something like:
' Do some step
worker.ReportProgress(10)

' Do some other step
worker.ReportProgress(20)

' Do another step
worker.ReportProgress(30)

' ... etc ...

Open in new window


You'll have to decide how many "steps" are in YOUR process and adjust the values that are hardcoded into ReportProgress() accordingly.

Hope that helps...
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Karen WilsonProgrammerAuthor Commented:
I put a timer in the system to perform increments of percent done.  It is working.  It is chugging along well until it's time to install SQL, then I get an error that it can't find the file.  I look in the directory, and it's there.  Everything is named correctly.

 ' This event handler is where the time-consuming work is done.
    Private Sub backgroundWorker1_DoWork(ByVal sender As System.Object, _
    ByVal e As DoWorkEventArgs) Handles BackgroundWorker1.DoWork

        Try

            Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)

            'Perform a time consuming operation and report progress.
            System.Threading.Thread.Sleep(500)

            'START THE FULL DOWNLOAD SQL EXPRESS AND HOME MANAGEMENT SYSTEM

            My.Computer.FileSystem.CreateDirectory("C:\HEREWEGO")
            My.Computer.Network.DownloadFile("http://desktophousewife.com/SQLEXPR_x64_ENU.exe", "C:\HEREWEGO\SQLEXPR_x64_ENU.exe", "", "", True, 500, True)


            Dim temppath As String = ControlChars.Quote & Path.Combine(Application.StartupPath, "C:\HEREWEGO\SQLEXPR_x64_ENU.exe") & ControlChars.Quote
            Dim processObj As Process = Process.Start(temppath, " /Q /X:C:\HEREWEGO\ExtractFile")

            '========HERE IT STOPS========
            processObj = Process.Start("C:\HEREWEGO\ExtractFile\setup.exe", "/q /Action=Install /IACCEPTSQLSERVERLICENSETERMS /Hideconsole /Features=SQLEngine /InstanceName=HEREWEGO /SQLSYSADMINACCOUNTS=""NT AUTHORITY\SYSTEM"" /SQLSVCACCOUNT=""NT AUTHORITY\SYSTEM"" /BROWSERSVCSTARTUPTYPE=""Automatic""")

            'Start download of home management system
            System.Diagnostics.Process.Start("http://desktophousewife.com/desktopHousewife.application")

        Catch ex As Exception
            MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Sub

Any suggestions?
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
You don't need the Sleep() calls:

    'Perform a time consuming operation and report progress.
    System.Threading.Thread.Sleep(500)

That is used to SIMULATE "work" in example code that doesn't actually do anything (otherwise the code would just run too fast and you wouldn't see that the progress bar works).

This line seems suspect to me:

    Dim temppath As String = ControlChars.Quote & Path.Combine(Application.StartupPath, "C:\HEREWEGO\SQLEXPR_x64_ENU.exe") & ControlChars.Quote

The SECOND part being supplied to Combine() already has a root in it "C:\", so it probably won't combine well with Application.StartupPath!
0
Karen WilsonProgrammerAuthor Commented:
That process works though.......  everything is in the directory.  I'm going to try making the sql install a new process in the code.
0
Karen WilsonProgrammerAuthor Commented:
That did not work.  I paused the program right before the start of
processObj = Process.Start("C:\HEREWEGO2\ExtractFile\setup.exe"  and it's there!!  

So then I deleted all the code before the line and it jumped past it and went to
  System.Diagnostics.Process.Start("http://desktophousewife.com/desktopHousewife.application") and it ran.  

Next trick - I ran the code, before it got to System.Diagnostics.Process.Start("http://desktophousewife.com/desktopHousewife.application"), I paused it.  Now SQL is installing and I have the instance listed in Microsoft SQL Server.  

I guess I need to pause the processes until they complete?
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
You can try WaitForExit()...though results vary based on how the external application was designed.

Something like:

        processObj = Process.Start("C:\HEREWEGO2\ExtractFile\setup.exe")
        processObj.WaitForExit()
0
Karen WilsonProgrammerAuthor Commented:
I am trying that right now.
0
Karen WilsonProgrammerAuthor Commented:
I think it worked!!  Now to try the whole thing on my dad.  :O)  I'll let you know if I have success!!  Thanks very much in the mean time.  I always cheer when I get Idle_Mind to respond.
0
Karen WilsonProgrammerAuthor Commented:
My dad isn't available for troubleshoot but you have answered the question.  Thanks so much for your time!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

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.