Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
consider there is a method

C#
public void codeCover
{
   //code for reading a XML file
}

i want to add a progress bar which progresses as the method starts and ends when the method completes

C#
private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
           
            codeCoverage();
            
            //as it takes int as a parameter i am not able to understand how do i check when the method starts and stops.
            backgroundWorker1.ReportProgress(i);
           
        }

        private void backgroundWorker1_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
        {
            progressBar1.Value = e.ProgressPercentage;
            label1.Text = e.ProgressPercentage.ToString() + "%";
        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
        {
            label1.Text = "completed!!";
        }

       
    }
Posted
Updated 8-Jun-15 6:11am
v2
Comments
Sergey Alexandrovich Kryukov 8-Jun-15 13:16pm    
I fixed your code formatting. Please click "Improve question" to see how it's done, to do it properly yourself, next time.
Your code makes no sense. How can you talk about "detecting" start and end of the method if you call it first and then create a progress bar. If you want to see the progress, do the notification inside the method.
—SA

1 solution

that depends on what your method is doing, normally your codeCoverage method has to report progress according to it's logic
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900