在子表单中创建一个BackgroundWorker,向父表单报告进度
我有一个包含两个表单的应用程序。我想为子窗体实现一个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将在您的子表单中创建一个父表单订阅的事件。在您的子表单中,每当后台工作人员触发 ProgressChanged 事件时,您基本上都会触发子表单向父表单公开的事件。
您还可以将子表单中的BackgroundWorker 公开给父表单,以便它可以订阅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: