Note that there are some explanatory texts on larger screens.

plurals
  1. POC# windows form progress bar with a function on background worker
    primarykey
    data
    text
    <p>I am attempting to add a progress bar (MARQUEE style) in my c# excel add in. The progress bar appears but it does not indicate any progress until the function is finished executing, meaning that it remains frozen.</p> <p>These are the functions in the Windows Form Class:</p> <pre><code> public void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { for (int i = 0; i &lt; 100; i++) { Thread.Sleep(100); //run in back thread backgroundWorker1.ReportProgress(i); } } //call back method public void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) { progressBar1.Value = e.ProgressPercentage; } //call back method public void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { progressBar1.Value = progressBar1.Maximum; } </code></pre> <p>This is how I call the function from the add in button:</p> <pre><code> private void buttonClicked(object sender, RibbonControlEventArgs e) { AddInPlanView.Form1 pBar = new AddInPlanView.Form1(); pBar.Visible = true; pBar.backgroundWorker1.WorkerReportsProgress = true; pBar.backgroundWorker1.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(pBar.backgroundWorker1_ProgressChanged); pBar.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(pBar.backgroundWorker1_DoWork); pBar.backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(pBar.backgroundWorker1_RunWorkerCompleted); pBar.backgroundWorker1.RunWorkerAsync(); FUNCTIONTORUN(); pBar.Visible = false; } </code></pre> <p>My code now attempts to put the progress bar on a background worker. I know I should switch this so that <code>FUNCTIONTORUN()</code> should be on a background worker, but how do I go about doing that? Since it is a marquee progress bar I do not need to update the value of the progress bar at all, it just needs to run until <code>FUNCTIONTORUN()</code> ends. Note that <code>FUNCTIONTORUN()</code> updates the cells of an Excel worksheet.</p> <p>The progress bar is initialized using the Visual Studio designer. The name of the <code>ProgressBar</code> object in the form class is <code>progressbar1</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload