Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

WinForm Progress Bar

Posted on 2011-09-14
6
Medium Priority
?
757 Views
Last Modified: 2012-05-12
I have 2 forms.  1 is the main form, which grabs some files, concatenates them together, then runs a seperate method to compress them using YUI Compressor.

The second form, is simply a ProgressBar form, that I fire up using .ShowDialog in the main routine

What I am trying to do is make the progress bar show progress during the compression process (because it takes a little bit),
but I don't seem to be doing it correctly, as all that shows it the blank progress bar.

default values of the control are Minimum =0 and Maximum = 100

Here's the code for the compressor sub:
 
Private Sub CompressTheFile(ByVal _TheFilePath As String)
        Dim _Progress As New Progress()
        _Progress.ShowDialog()
        Using _p As New Process
            With _p
                .StartInfo.FileName = "cmd.exe"
                .StartInfo.Arguments = "/C java -jar " & My.Application.Info.DirectoryPath & "\yuicompressor-2.4.6.jar " & _TheFilePath & " -o " & _TheFilePath
                .StartInfo.RedirectStandardOutput = True
                .StartInfo.UseShellExecute = False
                .StartInfo.CreateNoWindow = True
                .Start()
                For i = 0 To 10
                    Threading.Thread.Sleep(1)
                    _Progress.ProgressBar.Value += 1
                    _Progress.ProgressBar.Update()
                Next
                .WaitForExit()
            End With
        End Using
        _Progress.Close()
    End Sub

Open in new window


How can I make this work?
0
Comment
Question by:kevp75
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 40
ID: 36537320
Your Progress Bar form is _Progress, isn't it?

You are displaying it with ShowDialog. ShowDialog freezes the procedure until the form is closed. So you procedure does not even run when the form is on the screen.

Use Show instead.
0
 
LVL 25

Author Comment

by:kevp75
ID: 36537349
Ok.   Yes, _Progress is the Progress Bar form.

Ok, well...  now it's not freezing anymore LOL, but still no progress shown
0
 
LVL 25

Author Comment

by:kevp75
ID: 36537448
Ok.  I got it to work by changing the for loop to this:
For i = 0 To 100
                    Threading.Thread.Sleep(50)
                    _Progress.ProgressBar.Value = i
                    _Progress.ProgressBar.Update()
                Next

however, on some longer processes, the progress bar stops before the process is completed....  so, how do I get it to keep going until the process is completed?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 36537467
You're doing too much work...just set the Style() property of your ProgessBar to "Marquee" which makes it animate continuously.

Also, change up your routine to use the Exited() event of your Process so it doesn't lock up your main UI thread preventing the animation:
Private _Progress As Progress

    Private Sub CompressTheFile(ByVal _TheFilePath As String)
        Dim _p As New Process
        With _p
            _p.EnableRaisingEvents = True
            AddHandler _p.Exited, AddressOf _p_Exited
            .StartInfo.FileName = "cmd.exe"
            .StartInfo.FileName = "calc"
            .StartInfo.Arguments = "/C java -jar " & My.Application.Info.DirectoryPath & "\yuicompressor-2.4.6.jar " & _TheFilePath & " -o " & _TheFilePath
            .StartInfo.RedirectStandardOutput = True
            .StartInfo.UseShellExecute = False
            .StartInfo.CreateNoWindow = True
            .Start()
        End With
        _Progress = New Progress()
        _Progress.ShowDialog()
    End Sub

    Private Delegate Sub CloseIt(ByVal sender As Object, ByVal e As System.EventArgs)

    Private Sub _p_Exited(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not IsNothing(_Progress) AndAlso Not _Progress.IsDisposed Then
            If _Progress.InvokeRequired Then
                _Progress.BeginInvoke(New CloseIt(AddressOf _p_Exited), New Object() {sender, e})
            Else
                _Progress.Close()
                _Progress = Nothing
            End If
        End If
    End Sub

Open in new window

0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 36537472
Hehe...remove my line #9...  ;)
0
 
LVL 25

Author Comment

by:kevp75
ID: 36537551
But I really want to fire off the calculator ;o)

Much tthanks!!!
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question