Sync progressbar with cmd output

zackmark29

Active member
Joined
Apr 21, 2020
Messages
28
Programming Experience
Beginner
Hi everyone
I just wanna put new feature in my personal tool

Can you give me idea how I can sync progressbar to cmd output while still downloading

3kpywUg.png


This is the code I'm using for cmd output


VB.NET:
 Private Sub CMDOutput(StartFileName As String, StartFileArg As String)
        Dim process As Process = New Process()
        process.StartInfo.FileName = StartFileName
        process.StartInfo.Arguments = StartFileArg
        process.StartInfo.CreateNoWindow = True
        process.StartInfo.UseShellExecute = False
        process.StartInfo.RedirectStandardInput = True
        process.StartInfo.RedirectStandardOutput = True
        process.StartInfo.RedirectStandardError = True
        AddHandler process.OutputDataReceived, AddressOf Me.p_OutputDataReceived
        AddHandler process.ErrorDataReceived, AddressOf Me.p_ErrorDataReceived
        process.EnableRaisingEvents = True

        AddHandler process.Exited, New EventHandler(AddressOf Me.CmdProcess_Exited)

        process.Start()

        process.BeginOutputReadLine()
        process.BeginErrorReadLine()
    End Sub
 
A ProgessBar simply displays a ratio. It's up to you to calculate that ratio. What ratio do you want to display and how do you propose to calculate it? If you know that then you've answered your own question. If you don't know that then your question isn't really about the ProgressBar but the calculation. However you would calculate it manually is how you would do it in code.
 
A ProgessBar simply displays a ratio. It's up to you to calculate that ratio. What ratio do you want to display and how do you propose to calculate it? If you know that then you've answered your own question. If you don't know that then your question isn't really about the ProgressBar but the calculation. However you would calculate it manually is how you would do it in code.

Thank you for the reply.
I'm a newbie in vb.net and start learning progressbar

Could you give me example how I can run progressbar while cmd output still processing?

I have a message box pop-up when download finished
 
I don't think you really absorbed what I wrote. There's no such thing as "running a ProgessBar". A ProgressBar is simply a visual representation of a number. Would you say that you are "running a Label" if you use a Label to display different text at different times? I doubt it. Stop thinking of a ProgressBar as something magic. It's just a prettier version of a Label displaying a number. Just like a Label won't display a number that you haven't previously calculated and told it to display, neither will a ProgressBar. Stop thinking that the ProgressBar is going to do your work for you and start thinking about how you are going to do the work. First of all, what is the actual number you want the ProgressBar to display? Where does the value come from and how are you going to turn it into something the ProgressBar can represent, i.e. you need to know the total and the current values so that you can set the Maximum and the Value properties? Where is that data going to come from? That's for you to work out and perform, not the ProgressBar.
 
Think of it like this. Let's say that you are downloading a file and you want to display the progress. The ProgressBar doesn't know anything about the file or the download. All it knows about are the numbers you give it. You need to know the total size of the file and the amount downloaded so far so that you can set the Maximum and the Value to display the current progress. The ProgressBar doesn't know or care what those numbers mean or where they come from. It's for you to do the calculation based on the file download and then give those numbers to the ProgressBar to display. The same is true here. The ProgressBar doesn't know or care about your console output. It's up to you to extract the appropriate data from that output, perform the appropriate calculation and provide the appropriate numbers to the ProgressBar. Forget the Progresbar. That's the easy part. Start thinking about the extraction of the data and the calculation. That has nothing to do with ProgressBars.
 
Step 1 in measuring progress is knowing the final total. If you don't know that, you can't calculate the progress towards it. Presumably you want to express progress based on those "Downloading part N" lines. Do you know how many parts there are going to be? If not, you are dead at the first hurdle. If so, how are you going to get it and what do you think you need to do with it in relation to the ProgressBar?
 
Back
Top