如果我没有 UI,我应该使用 BackgroundWorker 类来处理任务队列吗?
我正在使用 .Net 3.5 (C#),并且我有一个任务队列,我想一个接一个地运行这些任务,我通过使用 BackgroundWorker 类(及其 DoWork、RunWorkerCompleted 和 IsBusy 方法和属性)来执行此操作。
1. 如果我没有任何UI,是否建议使用BackgroundWorker类?为什么?
2.我听说BackgroundWorker类已被弃用,是真的吗?有谁知道为什么吗?
3.还有其他课程可以帮助我完成上面提到的事情吗?
谢谢!
附注
我在第一个任务完成后立即运行第二个任务。
I'm using .Net 3.5 (C#) and I have a queue of tasks that I want to run one after the other, I'm doing that by using the BackgroundWorker class (with it's DoWork, RunWorkerCompleted and IsBusy methodes and property).
1. Is it recommended to use the BackgroundWorker class if I don't have any UI? why?
2. I heard that the BackgroundWorker class is deprecated, is it true? does anybody know why?
3. Is there another class that can help me to do what I have mentioned above?
Thanks!
P.S.
I'm running the second task just after the first one has finished.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您没有任何 UI,是否需要对另一个线程进行任何类型的编组?如果您一个接一个地运行任务,我会直接调用它们,除非您需要做任何更复杂的事情。如果您知道您确实需要在单独的线程中执行此操作,请发布有关您的要求的更多详细信息(包括这是什么类型的项目)。
据我所知,
BackgroundWorker
根本没有被弃用。在 C# 5 中,由于新的异步功能,它会变得不那么重要,但据我所知,它仍然可以毫无问题地使用。If you don't have any UI, do you need any sort of marshalling to another thread? If you're running the tasks one after another, I'd just call them directly unless you need to do anything more complicated. If you know you do need to do this in a separate thread, please post more details about your requirements (including what kind of project this is).
As far as I know,
BackgroundWorker
isn't deprecated at all. In C# 5 it will become somewhat less important due to the new async features, but it can still be used with no problems, as far as I'm aware.BackgroundWorker
类只是提供了一种更简单的使用线程的方法。和UI有一定的关系。请参阅 Jon Skeet 的回答和他的评论。所以,你可以继续使用它。http://msdn.microsoft.com/en-us/library /system.componentmodel.backgroundworker.aspx 没有提到BackgroundWorker 已被弃用。 因此,它并未被弃用。
BackgroundWorker
class just provides an easier way to use threads. It has some relation to UI. Please see Jon Skeet's answer and his comments.. So, you can continue to use it.http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx has no mention of BackgroundWorker being deprecated. So, it is not deprecated.