在子表单中创建一个BackgroundWorker,向父表单报告进度

发布于 2024-11-27 20:56:06 字数 214 浏览 2 评论 0原文

我有一个包含两个表单的应用程序。我想为子窗体实现一个BackgroundWorker,以便当它启动并且用户选择按钮时,将在BackgroundWorker上执行操作,子窗体将被隐藏,BackgroundWorker将向父窗体报告,以便进度栏可以更新,并且父表单仍然处于活动状态,因此用户在后台工作程序运行时仍然可以使用它。

任何对此的帮助将不胜感激。我只需要有人给我一个起点并帮助我指明正确的方向。

I have an application that contains two forms. I want to implement a BackgroundWorker for the Child Form so that when it is launched and a user selects a button the operations will be executed on the BackgroundWorker, the Child Form will be hidden, the BackgroundWorker will report to the Parent Form so that a progress bar can be updated, and the Parent Form is still active so a user can still use it while the BackgroundWorker is running.

Any help with this would be greatly appreciated. I just need someone to give me a starting point and help point me in the right direction.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故人如初 2024-12-04 20:56:06

我将在您的子表单中创建一个父表单订阅的事件。在您的子表单中,每当后台工作人员触发 ProgressChanged 事件时,您基本上都会触发子表单向父表单公开的事件。

您还可以将子表单中的BackgroundWorker 公开给父表单,以便它可以订阅ProgressChanged 事件。

编辑:
订阅事件:

backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);

I would create an event in your child form that the parent form subscribes to. In your child form whenever the ProgressChanged event is fired from your background worker you would basically fire the event that your child form exposes to the parent form.

You could also expose your BackgroundWorker in your child form to the parent form so that it could just subscribe to the ProgressChanged event.

Edit:
Subscribing to an event:

backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文