在BackgroundWorker中更新Winform上的状态
我有一个多步骤的BackgroundWorker 流程。我使用选取框进度条,因为其中几个步骤是在 iSeries 服务器上运行的,因此没有任何好的方法来确定百分比。我设想的是每一步后都会有更新的标签。您建议如何更新 winform 上的标签以反映每个步骤?
我想我会再补充一点。我通过 iSeries(或 IBM i 或 AS/400 或运行 OS/400 的中型计算机...呃...i5/OS(该死的 IBM 不保留相同的名称)上的存储过程调用一些 CL 和 RPG 程序年复一年))。
无论如何,我必须等到该步骤完全完成后才能继续在 winform 方面。我正在考虑向用户发送反馈,给出主要步骤。
- 将数据转储到 iSeries
- 运行月末
- 创建报告
- 上传最终结果
我可能应该在一开始就给出这一点。对此感到抱歉。我尽量让我的问题足够笼统,以便其他人稍后使用,而不是我的具体任务。
I have a multi-step BackgroundWorker process. I use a marquee progress bar because several of these steps are run on a iSeries server so there isn't any good way to determine a percentage. What I am envisioning is a label with updates after every step. How would you recommend updating a label on a winform to reflect each step?
Figured I would add a bit more. I call some CL and RPG programs via a stored procedure on an iSeries (or IBM i or AS/400 or a midrange computer running OS/400... er... i5/OS (damn you IBM for not keeping the same name year-to-year)).
Anyway I have to wait until that step is fully complete before I can continue on the winform side. I was thinking of sending feedback to the user giving the major steps.
- Dumping data to iSeries
- Running month-end
- Creating reports
- Uploading final results
I probably should have given this in the beginning. Sorry about that. I try to keep my questions general enough for others to make use of later rather than my specific task.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这本质上是后台工作者的要点之一。使用
ProgressBar
并根据您的算法确定进度有多远。(如前所述,如果通过率为 10%,则发送
10
,如果通过率为 50%,则发送50
)使用
BackgroundWorker
bgWrk添加以下事件:
在您认为值得用户更新的每个主要步骤之后,执行以下操作:
bgWrk.ReportProgress(intValue);
一些注意事项:
ReportProgress()
方法中传递Object
,因此您可以使用字符串对象等更新标签,但是进度条是仍然是“等等,我正在做某事”的通用符号如果您有任何不确定的轮询,并且您正在使用
ProgressBar
,尝试将其用作不确定的 ProgressBar,或旋转器等。 WPF 有一个内置属性可以使进度条不确定,这非常有用。This is one of the points of a background worker in essence. Use a
ProgressBar
and just determine how far along the progress is, according to your algorithm.(As has been mentioned, if they're 10% through, send
10
, if they're 50% through, send50
)Using a
BackgroundWorker
bgWrkAdd the following event:
After each major step that you think deserves a user updates do the following:
bgWrk.ReportProgress(intValue);
A couple of notes:
You can pass an
Object
as well in theReportProgress()
method, so you would be able to update a label with a string object etc, however a progress bar is still the universal symbol of "hold on, i'm doing something"If you have any indeterminate polling, and you are using a
ProgressBar
, try use it as an Indeterminate ProgressBar, or a spinner or such. WPF has a built in property to make a progress bar indeterminate which is useful.有多少步?如果有 10 个步骤,只需在成功完成的每个步骤的末尾使用 10% 的步骤标记即可。
How many steps is there? If there's 10 steps, simply use 10% step up marker for the end of each step that completed successfully.