如何通过检测方法的开始和结束来添加进度条? [英] How Do I Add Progressbar By Detecting Start And End Of A Method?

查看:83
本文介绍了如何通过检测方法的开始和结束来添加进度条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑有一种方法



consider there is a method

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



i想要添加一个进度条,该方法随着方法的开始而进行,并在方法完成时结束




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

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!!";
        }

       
    }

推荐答案

取决于你的方法在做什么,通常你的codeCoverage方法必须根据它的逻辑报告进度
that depends on what your method is doing, normally your codeCoverage method has to report progress according to it's logic


这篇关于如何通过检测方法的开始和结束来添加进度条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆