Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8337703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:22:33+00:00 2026-06-09T04:22:33+00:00

Good evening, I just started playing around with C# and I tried creating a

  • 0

Good evening,

I just started playing around with C# and I tried creating a GUI for a program that runs in command line. I have been able to get it running, but now I am stuck trying to implement a progress bar to it.

I have read other post but I am unable to find the exact issue or to understand how to apply the solution to my issue.

Here is my code (apologize if this is very messy):

private void MethodToProcess(Object sender, DoWorkEventArgs args)
    {
        // Set all the strings for passthrough
        String USMTPath_Work = USMTPath + USMTArch;
        String USMTPath_full = USMTPath_Work + @"\Scanstate.exe";
        String USMTFlags_Capture = @"/c /v:13 /o /l:scanstate.log /localonly /efs:copyraw";
        String Argument_full = SavePath + XML1 + XML2 + USMTFlags_Capture;

        // Test that USMT path is correct            
        if (USMTPath == null)
        {
            MessageBox.Show("Error: There is no USMT Path defined.");
            return;
        }

        // Test that Windows folder is correct when offline
        /* if (Windows_Path == null)
        {
            MessageBox.Show("Error: There is no Windows Path to capture.");
            return;
        } */

        // Runs the capture
        System.Diagnostics.Process Scanstate = new System.Diagnostics.Process();
        Scanstate.StartInfo.FileName = USMTPath_full;
        Scanstate.StartInfo.Arguments = Argument_full;
        Scanstate.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
        Scanstate.StartInfo.WorkingDirectory = USMTPath_Work;
        //Scanstate.StartInfo.UseShellExecute = false;
        Scanstate.StartInfo.CreateNoWindow = true;
        //Scanstate.StartInfo.RedirectStandardOutput = true;
        Scanstate.Start();
        Scanstate.WaitForExit();

        String Str_ExitCode = Scanstate.ExitCode.ToString();

        if (Scanstate.ExitCode == 1)
            MessageBox.Show("Error: Data has not been captured. Please check the log files for details.");
        if (Scanstate.ExitCode == 0)
            MessageBox.Show("Success: Data has been captured. For more information, check log files.");
        else
        {
            MessageBox.Show("Error: Unknown error has occurred. Please check the log files for details.");
            MessageBox.Show("Error Code: " + Str_ExitCode);
        }

        Scanstate.Close();

    }

Basically, I am trying to run the process scanstate.exe. Now, I am trying to run backgroundworker in order to be able to retrieve progress and pass it to the progressbar.

 private void btnCapture_Click(object sender, EventArgs e)
    {
        progressBar1.Minimum = 0;
        progressBar1.Maximum = 100;
        progressBar1.Step = 1;

        BackgroundWorker CaptureBG = new BackgroundWorker();
        CaptureBG.WorkerReportsProgress = true;
        CaptureBG.DoWork += new DoWorkEventHandler(MethodToProcess);
        CaptureBG.RunWorkerCompleted +=new RunWorkerCompletedEventHandler(CaptureBG_RunWorkerCompleted);
        CaptureBG.ProgressChanged += new ProgressChangedEventHandler(CaptureBG_ProgressChanged);
        CaptureBG.RunWorkerAsync();
    }

and

        private void CaptureBG_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs args)
    {
        progressBar1.Value = 100;
    }

    private void CaptureBG_ProgressChanged(object sender, ProgressChangedEventArgs args)
    {
        progressBar1.Value++;
    }

However I am either missunderstanding the use or I am missing something, since the process runs, but I don’t get any progress on the progressbar. It only fills once the process finish.

What am I doing wrong? In general, how would a process report progress if I don’t know exactly how long is going to take?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:22:35+00:00Added an answer on June 9, 2026 at 4:22 am

    The BackgroundWorker is responsible for updating the progress as it gets further complete with its task.

    There is no interaction between your process that you launch and your code that would provide progress of that process back to your code.

    In order for this to work, two things have to happen:

    1. You need to define a mechanism for your process to report progress to the BackgroundWorker.
    2. The BackgroundWorker must update its own progress by calling the ReportProgress method so that the ProgressChanged event is fired.

    The first step is the tricky one and depends on how scanstate.exe works. Does it do anything to give an indication of progress, such as write to the console? If so, you can redirect the console output and parse that output to determine or at least estimate progress.

    UPDATE

    Scanstate.exe provides the ability to write progress to a log, e.g.:

    scanstate /i:migapp.xml /i:miguser.xml \\fileserver\migration\mystore /progress:prog.log /l:scanlog.log
    

    You could use a FileWatcher in your BackgroundWorker to look for changes to the progress log and update progress accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good evening, I just started playing with Microsoft.Contracts (latest version) and plugging it on
Good evening, In my app that I'm currently developing, I have a class that
Good evening, i need to know how can i have one .h file that
Good evening I have a JTable that I built with a TableModel how to
Good evening :) I'm playing around with g++ and makefiles. I've gotten to this
Good Evening All, I have a textbox that needs to accept 14 digits plus
Good evening, I have a piece of code that toggles a drop-down menu. In
Good evening all! i have an Ajax call that loads 5 'echo's' from a
Good evening, I have a quick question that should be pretty easy, but for
Good evening guys. I'm currently trying to get started on development of a project

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.