如何在Backgroundworker中使用进度栏 [英] how to use Progress bar in backgroundworker

查看:287
本文介绍了如何在Backgroundworker中使用进度栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友....

我被BackGroundWorker困扰.我学习了与背景工作者一起工作的三个基本步骤.

步骤1:-DoWork事件-在此我们进行工作.即调用方法,函数,执行查询''等,还启用了诸如WorkerReportsProgress
之类的后台属性 ,WorkerSupportsCancellation等.

第2步:ProgressChanged事件:用于增加Progressbar的值,并启用访问表单控件.

步骤3:RunWorkerCompleted事件:告知工作是否完成.


但是我的问题是如何计算进度栏的最大值,如何增加进度栏,因为我必须调用不同的方法,有些方法将从数据库中检索值,有些方法将在应用程序中正常工作.我将样式更改为Marque并设置了 MarqueeAnimationSpeed ,但是由于大量处理,它隐藏了Progressbar.

如果我将所有方法都放在一个方法中,然后在DoWork事件中调用该方法,则它将隐藏进度栏.并在完成所有工作后显示出来.

如果我在DoWork事件中调用花费大量时间的部分. 通过在btn_Click事件上调用方法BackgrounfWorker.RunWorkerAsync(),然后在执行DoWork事件之前在执行所有这些操作之后在此方法下面执行行,然后在执行RunWorkAsync()方法.

请帮助我解决该问题.

Hi Friends....

I am stuck with BackGroundWorker. I learn Three basic steps to do work with Background worker.

Step 1 :- DoWork Event -- In this we do our work. i.e. Call Methods, Function, execute Querys'' etc. and also enables background Properties like WorkerReportsProgress
, WorkerSupportsCancellation etc.

Step 2: ProgressChanged event : This is used to increment Progressbar value,and enable''s access forms controls.

Step 3 : RunWorkerCompleted Event : It tells Work is completed or not .


But my problem is how to calculate max value for Progress Bar, how to increment Progress bar , because i have to call different methods some will retrieve values from Database, some will do work within the application. I changed style to Marque and set MarqueeAnimationSpeed but due to lot of Processing it hides the Progressbar.

If i put all methods in one Method then call that method in DoWork Event then it hides Progressbar. and shows it after doing all work.

If I call the part which take lot of time in DoWork event. by Calling method BackgrounfWorker.RunWorkerAsync() on btn_Click event then before going to DoWork Event it is executting lines bellow this method after executting all these then it is executting RunWorkAsync() method.

Please help me how to solve this Problem.

推荐答案

看看以下链接

http://www.dreamincode.net/forums/topic/112547 -using-the-backgroundworker-in-c%23/ [ BackgroundWorker和ProgressBar演示 [
take look of following links

http://www.dreamincode.net/forums/topic/112547-using-the-backgroundworker-in-c%23/[^]


BackgroundWorker and ProgressBar demo[^]



Hope you will get your answer..


这篇关于如何在Backgroundworker中使用进度栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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