0

Since the users of this application usually dump very large database, i thought it would be nice to show a progress bar on screen. The problem is that i don't know how i can do it.

ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "mysqldump.exe"
Process process = Process.Start(psi);
while (!process.StandardOutput.EndOfStream)
            {
                (sender as BackgroundWorker).ReportProgress(// insert percentage here));
                writer.Write((char)process.StandardOutput.Read());
            }
process.WaitForExit();
writer.Close();
process.Close();

this is a piece of my code, and i would like to send to report progress my percentage.

I know that mysqldump has something like --show-progress-size, but that should show the progress inside the shell, and since i'm running mysqldump from codebehind of my WPF application, i don't know how can i get that.

Daniele Sartori
  • 1,674
  • 22
  • 38
  • You are starting another process, the only way to display progress here is to display it without numbers (see [this](http://stackoverflow.com/q/23603711/1997232)). It is possible to use *hacky* way (similar to how antiviruses are working), e.g. [hooking file copy](http://stackoverflow.com/q/8201352/1997232), but that's complicated. Another option is to write yourself what that utility does. – Sinatr Apr 26 '17 at 15:40

1 Answers1

0

Since you don't know the amount of data in output, you cannot calculate the progress, because you don't know what 100% is. You can try to read the output line by line and parse the string, provided by --show-progress-size parameter. I think it looks like:

1000 of ~10000 rows dumped for table ...

You can use Regex to read the data or just parse the string and then calculate the progress.

Yevgeniy
  • 1,054
  • 1
  • 9
  • 17