实现自定义BackgroundWorker

发布于 2024-12-23 06:49:21 字数 333 浏览 4 评论 0原文

我正在尝试在 .NET 1.1 中实现 BackgroundWorker(因为没有),但我不太熟悉线程和委托。

现在我有一个名为BackgroundWorker 的类,其中包含一个名为DoWork 的方法。我知道我必须在 BackgroundWorker 中创建一个线程并在该线程中执行委托,但有两件事我还不太清楚。

  1. 如果 DoWork 收到无参数委托,如何在 BackgroundWorker 中启动线程?或者我应该使用委托以外的其他方法?

  2. 如何实现 ProgressChanged 事件?

I'm trying to implement a BackgroundWorker in .NET 1.1 (since there isn't any) and I'm not quite versed in threading and delegates.

Right now I have a class call BackgroundWorker with a method called DoWork. I know I must create a thread in the BackgroundWorker and execute a delegate in that thread, but there are two things I don't have quite clear yet.

  1. How can I start the thread in BackgroundWorker if DoWork receives a parameterless delegate? Or should I use another approach other than the delegate?

  2. How can I implement the ProgressChanged event?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文