-2

I'm developing a tool which does the following operations:

  • Download a zip file from a repository
  • Extract the zip file.
  • Run 5-6 exe/bat files from the extracted contents as separate Process.

I need to show a progress bar with approximate percentage completions for these operations. What would be the best way to do this?

Sandeep
  • 5,581
  • 10
  • 42
  • 62
  • @Downvoter: What's unclear/not usefull here? – Sandeep Oct 17 '12 at 09:36
  • Exactly the point that @AdiLester is making, you are just asking a solution, while If I google wpf progress bar, one of the results is WPF toolkit BusyIndicator. – Rik van den Berg Oct 17 '12 at 09:37
  • 3
    You're probably getting downvoted because you're not showing any of your own research and/or attempts at solutions. – J. Steen Oct 17 '12 at 09:38
  • @J.Steen: Ok. Might be. But I hope the same rule applies to all questions, such as http://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-in-c, where the same behavior can be seen. – Sandeep Oct 17 '12 at 09:49
  • @Sandeep It is, however, a question asked and answered by the same person in an effort to give people solutions without needing to ask the same question again. =) – J. Steen Oct 17 '12 at 09:52
  • @Rikkos: Do the BusyIndicator show percentage completions? – Sandeep Oct 17 '12 at 09:53
  • 1
    I don't get the downvotes While he could've been more specific about the problem he is facing, it is fairly a straight question and he's merely asking for a recommended approach, not asking "CAN I HAZ TEH CODEZ". Just because he hasn't shown any source code doesn't mean a guidance cannot be provided. – TtT23 Oct 17 '12 at 10:00
  • @Sandeep As far as the documentation goes, you can set the value of the progress bar. Take a look [Here](http://wpftoolkit.codeplex.com/wikipage?title=BusyIndicator) – Rik van den Berg Oct 17 '12 at 10:02
  • The best way it would be is to download a file, show the download progress on the `ProgressBar`, extract the archive and then to run some exe/bat files. – AgentFire Oct 17 '12 at 09:45

1 Answers1

4

What do you use to realize each point? Which libraries?

  • If you use some external, compiled libraries, you can catch the output and parse it:

    var proc = new Process {
        StartInfo = new ProcessStartInfo {
            FileName = "program.exe",
            Arguments = "command line arguments to your executable",
            UseShellExecute = false,
            RedirectStandardOutput = true,
            CreateNoWindow = true
        }
    };
    

And start the process:

proc.Start();
while (!proc.StandardOutput.EndOfStream) {
    string line = proc.StandardOutput.ReadLine();
    // parse your output
}
  • When you download a file, you can use just a simple pattern:

bytes_already_downloaded/bytes_total * 100 = download_progress_in_%

  • If you use some classes (you have source code), you can create a callback action:

    public void DoSomethingMethod(Action<int> progressCallback)
    {
        while(true)
        {
            // do something here
            // return the progress
            int progress = stuff_done / stuff_total * 100;
            progressCallback(progress);
        }
    }
    

And how to use it?

MyClass.DoSomethingMethod(delegate(int i) { progressBar.Progress = i; });

Or just:

MyClass.DoSomethingMethod(i => progressBar.Progress = i);

If you mean something else, you can specify it in the comment. I will try to answer:)

J. Steen
  • 15,470
  • 15
  • 56
  • 63
Nickon
  • 9,652
  • 12
  • 64
  • 119